本文整理匯總了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();
}
}
示例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);
}
示例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();
}
}
示例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;
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}