當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeMessage.saveChanges方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeMessage.saveChanges方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.saveChanges方法的具體用法?Java MimeMessage.saveChanges怎麽用?Java MimeMessage.saveChanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeMessage的用法示例。


在下文中一共展示了MimeMessage.saveChanges方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createMimeMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 *
 * @param session 和服務器交互的會話
 * @param mail 郵件內容
 * @return
 * @throws Exception
 */
private static MimeMessage createMimeMessage(Session session, String SendAccount, Mail mail) throws Exception {
    MimeMessage message = new MimeMessage(session);
    //From: 發件人
    message.setFrom(new InternetAddress(SendAccount, mail.getPersonal(), "UTF-8"));
    // To: 收件人
    message.setRecipients(MimeMessage.RecipientType.TO, mail.getAddresses());
    // Subject: 郵件主題
    message.setSubject(mail.getSubject(), "UTF-8");
    // Content: 郵件正文(可以使用html標簽)
    message.setContent(mail.getContext(), "text/html;charset=UTF-8");
    // 設置發件時間
    message.setSentDate(new Date());
    message.saveChanges();
    return message;
}
 
開發者ID:BetaSummer,項目名稱:sztw,代碼行數:23,代碼來源:MailCore.java

示例2: sendHtmlEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendHtmlEmail(EmailObject email) throws Exception {
    // 創建Session實例對象
    Session session = Session.getInstance(props, new EmailAuthenticator());

    // 創建MimeMessage實例對象
    MimeMessage message = new MimeMessage(session);
    // 設置郵件主題
    message.setSubject(email.getEmailSubject(),"utf-8");
    // 設置發送人
    message.setFrom(new InternetAddress(from));
    // 設置發送時間
    message.setSentDate(new Date());
    // 設置收件人
    message.setRecipients(MimeMessage.RecipientType.TO, InternetAddress.parse(email.getToEmail()));
    // 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
    message.setContent(email.getEmailContent(), "text/html;charset=utf-8");
    // 保存並生成最終的郵件內容
    message.saveChanges();
    // 發送郵件
    Transport.send(message);
    //記錄郵件發送日誌
    SendEmailLog sendEmailLog = new SendEmailLog();
    sendEmailLog.setToemail(email.getToEmail());
    sendEmailLog.setSubject(email.getEmailSubject());
    sendEmailLog.setSenddate(new Date());
    sendEmailLog.setContent(email.getEmailContent());
    sendEmailLogDao.insert(sendEmailLog);
}
 
開發者ID:NeilRen,項目名稱:NEILREN4J,代碼行數:29,代碼來源:EmailUtils.java

示例3: buildEmailMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private Message buildEmailMessage(EmailInfo emailInfo)
		throws AddressException, MessagingException, UnsupportedEncodingException {
	MimeMessage message = new MimeMessage(this.session);
	message.setFrom(new InternetAddress(emailInfo.getFrom(), "網頁更新訂閱係統", "UTF-8"));
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));

	Multipart multipart = new MimeMultipart();
	BodyPart messageBodyPart = new MimeBodyPart();
	messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
	multipart.addBodyPart(messageBodyPart);
	message.setContent(multipart);
	message.setSubject(emailInfo.getTitle());
	message.saveChanges();
	return message;
}
 
開發者ID:wrayzheng,項目名稱:webpage-update-subscribe,代碼行數:16,代碼來源:EmailServer.java

示例4: send

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Override
public void send(String senderAddress, String senderName, String recipient, String content) {
    if (StringUtils.isBlank(senderAddress)) {
        throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
                "You must set a value for notifications to work");
    }

    if (StringUtils.isBlank(content)) {
        throw new InternalServerError("Notification content is empty");
    }

    try {
        InternetAddress sender = new InternetAddress(senderAddress, senderName);
        MimeMessage msg = new MimeMessage(session, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
        msg.setHeader("X-Mailer", "mxisd"); // FIXME set version
        msg.setSentDate(new Date());
        msg.setFrom(sender);
        msg.setRecipients(Message.RecipientType.TO, recipient);
        msg.saveChanges();

        log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
        SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
        transport.setStartTLS(cfg.getTls() > 0);
        transport.setRequireStartTLS(cfg.getTls() > 1);

        log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort());
        transport.connect(cfg.getHost(), cfg.getPort(), cfg.getLogin(), cfg.getPassword());
        try {
            transport.sendMessage(msg, InternetAddress.parse(recipient));
            log.info("Invite to {} was sent", recipient);
        } finally {
            transport.close();
        }
    } catch (UnsupportedEncodingException | MessagingException e) {
        throw new RuntimeException("Unable to send e-mail invite to " + recipient, e);
    }
}
 
開發者ID:kamax-io,項目名稱:mxisd,代碼行數:38,代碼來源:EmailSmtpConnector.java

示例5: createMimeMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * 創建一封隻包含文本的簡單郵件
 *
 * @param session
 *            和服務器交互的會話
 * @param sendMail
 *            發件人郵箱
 * @param receiveMail
 *            收件人郵箱
 * @return
 * @throws Exception
 */
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String username,String pwd)
		throws Exception {
	// 1. 創建一封郵件
	MimeMessage message = new MimeMessage(session);

	// 2. From: 發件人(昵稱有廣告嫌疑,避免被郵件服務器誤認為是濫發廣告以至返回失敗,請修改昵稱)
	message.setFrom(new InternetAddress(sendMail, "Mircle", "UTF-8"));

	// 3. To: 收件人(可以增加多個收件人、抄送、密送)
	message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "", "UTF-8"));

	// 4. Subject: 郵件主題(標題有廣告嫌疑,避免被郵件服務器誤認為是濫發廣告以至返回失敗,請修改標題)
	message.setSubject(subject, "UTF-8");

	// 5. Content: 郵件正文(可以使用html標簽)(內容有廣告嫌疑,避免被郵件服務器誤認為是濫發廣告以至返回失敗,請修改發送內容)
	message.setContent(getContent(username,pwd), "text/html;charset=UTF-8");

	// 6. 設置發件時間
	message.setSentDate(new Date());

	// 7. 保存設置
	message.saveChanges();

	return message;
}
 
開發者ID:miracle857,項目名稱:weibo,代碼行數:38,代碼來源:Mail.java

示例6: sendAccountActivateEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void sendAccountActivateEmail(String email, String uuid, int userId) {
  Session session;
  try {
    session = getSession();
    MimeMessage message = new MimeMessage(session);
    message.setSubject("������֤��");
    message.setSentDate(new Date());
    message.setFrom(new InternetAddress(FROM));
    message.setRecipient(RecipientType.TO, new InternetAddress(email));
    message.setContent("�����û�"+userId+":������֤��Ϊ��"+uuid,
        "text/html;charset=utf-8");
    message.saveChanges();
    Transport.send(message);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
開發者ID:Luodian,項目名稱:Higher-Cloud-Computing-Project,代碼行數:18,代碼來源:EmailUtils.java

示例7: createFeedBackMsg

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * 創建一封反饋郵件
 * @param session
 * @param sendMail
 * @param detail
 * @return
 */
private MimeMessage createFeedBackMsg(Session session, String sendMail, String detail) throws UnsupportedEncodingException, MessagingException {
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(sendMail, "吃在華科", "UTF-8"));
    message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("[email protected]", this.name, "UTF-8"));
    message.setSubject("吃在華科用戶反饋", "UTF-8");
    String content = UserStatus.getUserStatus().getName()+"\n"+detail;
    message.setContent(content, "text/html;charset=UTF-8");
    message.setSentDate(new Date());
    message.saveChanges();
    return message;
}
 
開發者ID:GrayXu,項目名稱:HustEating,代碼行數:19,代碼來源:Mail.java

示例8: send

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * 發送郵件
 * @param receiver 接收者郵箱地址
 * @param subject 郵件主題
 * @param content 郵件內容
 */
public static void send(String receiver, String subject, String content) {
    try {
        //設置SSL連接、郵件環境
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
        Properties props = System.getProperties();
        props.setProperty("mail.smtp.host", SMTP_HOST);
        props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.port", SMTP_PORT);
        props.setProperty("mail.smtp.socketFactory.port", SMTP_SOCKET_FACTORY_PORT);
        props.setProperty("mail.smtp.auth", "true");
        //建立郵件會話
        Session session = Session.getDefaultInstance(props, new Authenticator() {
            //身份認證
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(SENDER, PASSWORD);
            }
        });
        //建立郵件對象
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(SENDER, SENDER_NAME));
        message.setRecipients(Message.RecipientType.TO, receiver);
        message.setSubject(subject);

        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setContent(content, "text/html;charset=UTF-8");
        MimeMultipart mimeMultipart = new MimeMultipart();
        mimeMultipart.addBodyPart(mimeBodyPart);

        message.setContent(mimeMultipart);
        message.saveChanges();

        Transport.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:jthinking,項目名稱:linux-memory-monitor,代碼行數:45,代碼來源:JavaMail.java

示例9: send

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void send(String to, String cc, String bcc, String subject,
        String content, JavamailConfig javamailConfig)
        throws MessagingException {
    logger.debug("send : {}, {}", to, subject);

    try {
        Properties props = createSmtpProperties(javamailConfig);
        String username = javamailConfig.getUsername();
        String password = javamailConfig.getPassword();

        // 創建Session實例對象
        Session session = Session.getInstance(props, new SmtpAuthenticator(
                username, password));
        session.setDebug(false);

        // 創建MimeMessage實例對象
        MimeMessage message = new MimeMessage(session);
        // 設置郵件主題
        message.setSubject(subject);
        // 設置發送人
        message.setFrom(new InternetAddress(username));
        // 設置發送時間
        message.setSentDate(new Date());
        // 設置收件人
        message.setRecipients(RecipientType.TO, InternetAddress.parse(to));
        // 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
        message.setContent(content, "text/html;charset=gbk");

        // 保存並生成最終的郵件內容
        message.saveChanges();

        // 發送郵件
        Transport.send(message);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:38,代碼來源:JavamailService.java

示例10: sendAccountActiveEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/** 發送用戶驗證的郵件 */
public static void sendAccountActiveEmail(User user) {

	String subject = "sdudoc郵箱驗證提醒";
	String content = "感謝您於" + DocUtil.getDateTime() + "在sdudoc注冊,複製以下鏈接,即可完成安全驗證:"
			+ "http://127.0.0.1:8080/sdudoc/activeUser.action?user.username=" + user.getUsername()
			+ "&user.checkCode=" + user.getCheckCode() + " 為保障您的帳號安全,請在24小時內點擊該鏈接,您也可以將鏈接複製到瀏覽器地址欄訪問。"
			+ "若您沒有申請過驗證郵箱 ,請您忽略此郵件,由此給您帶來的不便請諒解。";

	// session.setDebug(true);

	String from = "[email protected]"; // 發郵件的出發地(發件人的信箱)
	Session session = getMailSession();
	// 定義message
	MimeMessage message = new MimeMessage(session);
	try {
		// 設定發送郵件的地址
		message.setFrom(new InternetAddress(from));
		// 設定接受郵件的地址
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
		// 設定郵件主題
		message.setSubject(subject);
		// 設定郵件內容
		BodyPart mdp = new MimeBodyPart();// 新建一個存放信件內容的BodyPart對象
		mdp.setContent(content, "text/html;charset=utf8");// 給BodyPart對象設置內容和格式/編碼方式
		Multipart mm = new MimeMultipart();// 新建一個MimeMultipart對象用來存放BodyPart對
		// 象(事實上可以存放多個)
		mm.addBodyPart(mdp);// 將BodyPart加入到MimeMultipart對象中(可以加入多個BodyPart)
		message.setContent(mm);// 把mm作為消息對象的內容
		// message.setText(content);
		message.saveChanges();
		Transport.send(message);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:37,代碼來源:MailUtil.java

示例11: sendResetPasswordEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/** 發送密碼重置的郵件 */
public static void sendResetPasswordEmail(User user) {
	String subject = "sdudoc密碼重置提醒";
	String content = "您於" + DocUtil.getDateTime() + "在sdudoc找回密碼,點擊以下鏈接,進行密碼重置:"
			+ "http://127.0.0.1:8080/sdudoc/resetPasswordCheck.action?user.username=" + user.getUsername()
			+ "&user.checkCode=" + user.getCheckCode() + " 為保障您的帳號安全,請在24小時內點擊該鏈接,您也可以將鏈接複製到瀏覽器地址欄訪問。"
			+ "若您沒有申請密碼重置,請您忽略此郵件,由此給您帶來的不便請諒解。";

	// session.setDebug(true);

	String from = "[email protected]"; // 發郵件的出發地(發件人的信箱)
	Session session = getMailSession();
	// 定義message
	MimeMessage message = new MimeMessage(session);
	try {
		message.setFrom(new InternetAddress(from));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
		message.setSubject(subject);
		BodyPart mdp = new MimeBodyPart();
		mdp.setContent(content, "text/html;charset=utf8");
		Multipart mm = new MimeMultipart();
		mm.addBodyPart(mdp);
		message.setContent(mm);
		message.saveChanges();
		Transport.send(message);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:30,代碼來源:MailUtil.java

示例12: createAttachMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
  * @Method: createAttachMail
  * @Description: ����һ����������ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createAttachMail(String subject, String content, String filePath) throws Exception{
      MimeMessage message = new MimeMessage(session);
      
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(attach);
      mp.setSubType("mixed");
      
      message.setContent(mp);
      message.saveChanges();
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:41,代碼來源:EmailUtil.java

示例13: createImageMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
  * @Method: createImageMail
  * @Description: ����һ���ʼ����Ĵ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createImageMail(String subject, String content, String imagePath) throws Exception {

      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      MimeBodyPart image = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(imagePath));
      image.setDataHandler(dh);
      image.setContentID("xxx.jpg");
      MimeMultipart mm = new MimeMultipart();
      mm.addBodyPart(text);
      mm.addBodyPart(image);
      mm.setSubType("related");

      message.setContent(mm);
      message.saveChanges();
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:39,代碼來源:EmailUtil.java

示例14: createMixedMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
  * @Method: createMixedMail
  * @Description: ����һ��������ʹ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createMixedMail(String subject, String content, String imagePath, String filePath) throws Exception {
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content,"text/html;charset=UTF-8");
      
      MimeBodyPart image = new MimeBodyPart();
      image.setDataHandler(new DataHandler(new FileDataSource(imagePath)));
      image.setContentID("aaa.jpg");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(image);
      mp.setSubType("related");
      
      MimeBodyPart bodyContent = new MimeBodyPart();
      bodyContent.setContent(mp);
      message.saveChanges();
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:46,代碼來源:EmailUtil.java

示例15: buildMailMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage buildMailMessage(Session session, NotificationEvent notifyEvent, String title,
        String mailTemplatePath) throws MessagingException {

    MimeMessage message = new MimeMessage(session);

    // 郵件標題
    message.setSubject(title);

    String html = IOHelper.readTxtFile(mailTemplatePath, "utf-8");
    html = buildMailBody(html, notifyEvent);
    // 正文
    message.setContent(html, "text/html;charset=utf-8");
    // 發件人
    message.setFrom(username);

    String addressStr = notifyEvent.getArg(cName);
    String[] toAddr = addressStr.split(",");
    Address[] receiver = new Address[toAddr.length];
    int i = 0;
    for (String addr : toAddr) {
        if (!StringHelper.isEmpty(addr)) {
            receiver[i] = new InternetAddress(addr);
            i++;
        }
    }
    // 收件人
    message.setRecipients(MimeMessage.RecipientType.TO, receiver);

    message.saveChanges();

    return message;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:33,代碼來源:JavaMailAction.java


注:本文中的javax.mail.internet.MimeMessage.saveChanges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。