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


Java JavaMailSenderImpl.createMimeMessage方法代碼示例

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


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

示例1: sendMailWithUsername

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithUsername(
        @NotBlank @Email final String email,
        @NotBlank final String username
) {
    log.info("Called with e-mail {}, username {}", email, username);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Recover username");
        helper.setText("Your username: " + "<b>" + username + "</b>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:28,代碼來源:MailServiceImpl.java

示例2: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public void sendMail(final String from, final String to,
    final String subject, final String msg) throws MessagingException {

  // final SimpleMailMessage message = new SimpleMailMessage();
  // message.setFrom(from);
  // message.setTo(to);
  // message.setSubject(subject);
  // message.setText(msg);
  // mailSender.send(message);

  // final JavaMailSenderImpl sender = new JavaMailSenderImpl();
  mailSender = new JavaMailSenderImpl();
  final MimeMessage mimeMessage = mailSender.createMimeMessage();
  final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false,
      "utf-8");
  final String htmlMsg = msg;
  mimeMessage.setContent(htmlMsg, "text/html");
  helper.setTo(to);
  helper.setSubject(subject);
  helper.setFrom(from);
  mailSender.send(mimeMessage);

}
 
開發者ID:AURIN,項目名稱:workbenchauth,代碼行數:24,代碼來源:classMail.java

示例3: sendMailWithNewPassword

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithNewPassword(
        @NotBlank @Email final String email,
        @NotBlank final String newPassword
) {
    log.info("Called with e-mail {}, newPassword {}", email, newPassword);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Recover password");
        helper.setText("Your new password: " + "<b>" + newPassword + "</b>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:28,代碼來源:MailServiceImpl.java

示例4: send

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public boolean send(String to, String subject, String text, String unsubscribeUrl) {
	try {
		JavaMailSenderImpl sender = (JavaMailSenderImpl) mailSender;
		MimeMessage mail = sender.createMimeMessage();
		mail.setContent(text.replaceAll("\n", "<br\\>\n").trim(),
				"text/html; charset=UTF-8");
		MimeMessageHelper helper = new MimeMessageHelper(mail, false,
				"UTF-8");
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		if (null != unsubscribeUrl) {
			mail.addHeader("List-Unsubscribe", String.format("<%s>", unsubscribeUrl));
		}
		sender.send(mail);
		LOG.trace("E-mail sent with subject: {}", subject);
		return true;
	} catch (Exception ex) {
		LOG.warn("Failed to send email (subject: " + subject + ").", ex);
		return false;
	}
}
 
開發者ID:petabyte-research,項目名稱:redflags,代碼行數:23,代碼來源:EmailSvc.java

示例5: sendEmail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public void sendEmail() throws MessagingException {
    String email = backup.getEmail();
    JavaMailSenderImpl mailimpl = new JavaMailSenderImpl();
    mailimpl.setHost("smtp.163.com");
    MimeMessage mailMsg = mailimpl.createMimeMessage();
    MimeMessageHelper msgHelper = new MimeMessageHelper(mailMsg,true,"utf8");
    //set sender,receiver
    msgHelper.setTo(backup.getToemail());
    msgHelper.setFrom(email);
    msgHelper.setSubject("數據庫備份");
    msgHelper.setText("<html><head></head><body><h1>數據庫備份</h1></body></html>",true);

    msgHelper.addAttachment("study.sql",new File(backup.getSavePath() + File.separator + "study.sql"));
    msgHelper.addAttachment("blog.sql",new File(backup.getSavePath() + File.separator + "blog.sql"));

    mailimpl.setUsername(email);
    mailimpl.setPassword("liubo704");
    Properties prop = new Properties();
    prop.put("mail.smtp.auth",true);
    prop.put("mail.smtp.timeout","25000");

    mailimpl.setJavaMailProperties(prop);
    mailimpl.send(mailMsg);
}
 
開發者ID:ycsoft,項目名稱:SweetHeart,代碼行數:25,代碼來源:BackupController.java

示例6: sendMailWithActivationToken

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithActivationToken(
        @NotBlank @Email final String email,
        @NotBlank final String token
) {
    log.info("Called with e-mail {}, token {}", email, token);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Complete registration");
        helper.setText("To activation your account, click the link below:<br />"
                + "<a href='" + "https://localhost:8443" + "/register/thanks?token=" + token + "'>" +
                "Click here to complete your registration" +
                "</a>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:31,代碼來源:MailServiceImpl.java

示例7: sendMailWithEmailChangeToken

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithEmailChangeToken(
        @NotBlank @Email final String email,
        @NotBlank final String token
) {
    log.info("Called with e-mail {}, token {}", email, token);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Change e-mail");
        helper.setText("Change e-mail address, click the link below:<br />"
                + "<a href='" + "https://localhost:8443" + "/settings/changeEmail/thanks?token=" + token + "'>" +
                "Click here to complete the change of your e-mail" +
                "</a>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:31,代碼來源:MailServiceImpl.java

示例8: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void sendMail(JavaMailSenderImpl mailSender, String mailFrom, String email, String subject, String message)
    throws IoTPException {
  try {
    MimeMessage mimeMsg = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, "UTF-8");
    helper.setFrom(mailFrom);
    helper.setTo(email);
    helper.setSubject(subject);
    helper.setText(message, true);
    mailSender.send(helper.getMimeMessage());
  } catch (Exception e) {
    throw handleException(e);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:15,代碼來源:DefaultMailService.java

示例9: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void sendMail(JavaMailSenderImpl mailSender, 
        String mailFrom, String email, 
        String subject, String message) throws ThingsboardException {
    try {
        MimeMessage mimeMsg = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, UTF_8);
        helper.setFrom(mailFrom);
        helper.setTo(email);
        helper.setSubject(subject);
        helper.setText(message, true);
        mailSender.send(helper.getMimeMessage());
    } catch (Exception e) {
        throw handleException(e);
    }
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:16,代碼來源:DefaultMailService.java

示例10: buildMessage

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private MimeMessage buildMessage(SUser user, SmtpConfig config, JavaMailSenderImpl sender) throws MessagingException {
    MimeMessage message = sender.createMimeMessage();
    message.setFrom(config.getFromAddress());
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
    message.setSubject("TeamCity password reset");
    message.setText(getMessageBody(user));
    return message;
}
 
開發者ID:dbf256,項目名稱:teamcity-password-reset-plugin,代碼行數:9,代碼來源:PasswordResetController.java

示例11: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * 發送郵件 (完整版) (純JavaMail)
 * 
 * @param toAddress		: 收件人郵箱
 * @param mailSubject	: 郵件主題
 * @param mailBody		: 郵件正文
 * @param mailBodyIsHtml: 郵件正文格式,true:HTML格式;false:文本格式
 * //@param inLineFile	: 內嵌文件
 * @param attachments	: 附件
 */
public static boolean sendMail (String toAddress, String mailSubject, String mailBody, 
		boolean mailBodyIsHtml, File[] attachments){
       try {
		// 創建郵件發送類 JavaMailSender (用於發送多元化郵件,包括附件,圖片,html 等)
       	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
       	mailSender.setHost(host); 			// 設置郵件服務主機    
       	mailSender.setUsername(username); 	// 發送者郵箱的用戶名    
       	mailSender.setPassword(password); 	// 發送者郵箱的密碼    
       	
		// 配置文件,用於實例化java.mail.session
		Properties pro = new Properties();
		pro.put("mail.transport.protocol", "smtp");
		pro.put("mail.smtp.auth", "true");		// 登錄SMTP服務器,需要獲得授權 (網易163郵箱新近注冊的郵箱均不能授權,測試 sohu 的郵箱可以獲得授權)
		pro.put("mail.smtp.socketFactory.port", port);
		pro.put("mail.smtp.socketFactory.fallback", "false");
		mailSender.setJavaMailProperties(pro);
		
		// 創建多元化郵件 (創建 mimeMessage 幫助類,用於封裝信息至 mimeMessage)
		MimeMessage mimeMessage = mailSender.createMimeMessage();						
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8");
		
		helper.setFrom(username, sendNick);
		helper.setTo(toAddress);

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml); 
		
		// 設置收件人抄送的名片和地址(相當於群發)
		//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("郵箱001") + " <@163.com>," + MimeUtility.encodeText("郵箱002") + " <@foxmail.com>"));

		// 內嵌文件,第1個參數為cid標識這個文件,第2個參數為資源
		//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);
		
		// 添加附件
		/*if (ArrayUtils.isNotEmpty(attachments)) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}*/

		// 群發
		//MimeMessage[] mailMessages = { mimeMessage };
		
		mailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return false;
}
 
開發者ID:mmwhd,項目名稱:stage-job,代碼行數:61,代碼來源:MailUtil.java

示例12: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * 發送郵件 (完整版) (純JavaMail)
 * 
 * @param toAddress		: 收件人郵箱
 * @param mailSubject	: 郵件主題
 * @param mailBody		: 郵件正文
 * @param mailBodyIsHtml: 郵件正文格式,true:HTML格式;false:文本格式
 * //@param inLineFile	: 內嵌文件
 * @param attachments	: 附件
 */
public static boolean sendMail (String toAddress, String mailSubject, String mailBody, 
		boolean mailBodyIsHtml, File[] attachments){
       try {
		// 創建郵件發送類 JavaMailSender (用於發送多元化郵件,包括附件,圖片,html 等    )
       	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
       	mailSender.setHost(host); 			// 設置郵件服務主機    
       	mailSender.setUsername(username); 	// 發送者郵箱的用戶名    
       	mailSender.setPassword(password); 	// 發送者郵箱的密碼    
       	
		//配置文件,用於實例化java.mail.session    
		Properties pro = new Properties();
		pro.put("mail.smtp.auth", "true");		// 登錄SMTP服務器,需要獲得授權 (網易163郵箱新近注冊的郵箱均不能授權,測試 sohu 的郵箱可以獲得授權)
		pro.put("mail.smtp.socketFactory.port", port);
		pro.put("mail.smtp.socketFactory.fallback", "false");
		mailSender.setJavaMailProperties(pro);
		
		//創建多元化郵件 (創建 mimeMessage 幫助類,用於封裝信息至 mimeMessage)
		MimeMessage mimeMessage = mailSender.createMimeMessage();						
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8");
		
		helper.setFrom(sendFrom, sendNick);
		helper.setTo(toAddress);

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml); 
		
		// 添加內嵌文件,第1個參數為cid標識這個文件,第2個參數為資源
		//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);	
		
		// 添加附件    
		if (ArrayUtils.isNotEmpty(attachments)) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}
		
		mailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
開發者ID:kevinKaiF,項目名稱:xxl-job,代碼行數:54,代碼來源:MailUtil.java

示例13: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
 * 發送郵件 (完整版) (純JavaMail)
 * 
 * @param toAddress		: 收件人郵箱
 * @param mailSubject	: 郵件主題
 * @param mailBody		: 郵件正文
 * @param mailBodyIsHtml: 郵件正文格式,true:HTML格式;false:文本格式
 * @param attachments	: 附件
 */
public static boolean sendMail (String toAddress, String mailSubject, String mailBody, 
		boolean mailBodyIsHtml, File[] attachments){
       try {
		// 創建郵件發送類 JavaMailSender (用於發送多元化郵件,包括附件,圖片,html 等    )
       	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
       	mailSender.setHost(host); 			// 設置郵件服務主機    
       	mailSender.setUsername(username); 	// 發送者郵箱的用戶名    
       	mailSender.setPassword(password); 	// 發送者郵箱的密碼    
       	
		//配置文件,用於實例化java.mail.session    
		Properties pro = System.getProperties();
           pro.put("mail.transport.protocol", "smtp");
		pro.put("mail.smtp.auth", "true");		// 登錄SMTP服務器,需要獲得授權 (網易163郵箱新近注冊的郵箱均不能授權,測試 sohu 的郵箱可以獲得授權)
		pro.put("mail.smtp.socketFactory.port", port);
		pro.put("mail.smtp.socketFactory.fallback", "false");
		mailSender.setJavaMailProperties(pro);
		
		//創建多元化郵件 (創建 mimeMessage 幫助類,用於封裝信息至 mimeMessage)
		MimeMessage mimeMessage = mailSender.createMimeMessage();						
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, (attachments!=null && attachments.length>0), "UTF-8");
		
		helper.setFrom(username, sendNick);
		helper.setTo(toAddress);

		helper.setSubject(mailSubject);
		helper.setText(mailBody, true);

           // 設置收件人抄送的名片和地址(相當於群發)
           //helper.setCc(InternetAddress.parse(MimeUtility.encodeText("郵箱001") + " <@163.com>," + MimeUtility.encodeText("郵箱002") + " <@foxmail.com>"));

		// 添加內嵌文件,第1個參數為cid標識這個文件,第2個參數為資源
		//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);	
		
		// 添加附件    
		if (attachments!=null && attachments.length>0) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}

           // 群發
           //MimeMessage[] mailMessages = { mimeMessage };
		
		mailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:60,代碼來源:MailUtil.java


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