本文整理汇总了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;
}