use of org.springframework.mail.javamail.MimeMessageHelper in project waltz by khartec.
the class WaltzEmailer method sendEmail.
public void sendEmail(String subject, String body, String[] to) {
Checks.checkNotEmpty(subject, "subject cannot be empty");
Checks.checkNotEmpty(body, "body cannot be empty");
Checks.checkNotEmpty(to, "to cannot be empty");
Checks.checkAll(to, StringUtilities::notEmpty, "email address cannot be empty");
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);
message.setSubject(subject);
message.setFrom(fromEmail);
message.setBcc(to);
message.addAttachment("waltz.png", IOUtilities.getFileResource("/images/waltz.png"));
message.addAttachment("client-logo", IOUtilities.getFileResource("/templates/images/client-logo.png"));
Map model = new HashMap();
model.put("body", body);
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
try (InputStreamReader templateReader = new InputStreamReader(IOUtilities.getFileResource(DEFAULT_EMAIL_TEMPLATE_LOCATION).getInputStream())) {
Template template = new Template("template", templateReader, cfg);
String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project zhcet-web by zhcet-amu.
the class EmailService method constructEmail.
private MimeMessage constructEmail(String emailAddress, String subject, String body, String[] bcc) throws MessagingException {
MimeMessage mimeMessage = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
helper.setText(body);
setBasicInfo(helper, senderEmail, emailAddress, subject, bcc);
return mimeMessage;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project paascloud-master by paascloud.
the class OptSendMailServiceImpl method getMimeMessage.
private MimeMessage getMimeMessage(String subject, String text, Set<String> to) {
Preconditions.checkArgument(!PubUtils.isNull(subject, text, to), "参数异常, 邮件信息不完整");
String[] toArray = setToArray(to);
Preconditions.checkArgument(PublicUtil.isNotEmpty(toArray), "请输入收件人邮箱");
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom(from);
helper.setTo(toArray);
helper.setSubject(subject);
helper.setText(text, true);
} catch (MessagingException e) {
log.error("生成邮件消息体, 出现异常={}", e.getMessage(), e);
throw new OpcBizException(ErrorCodeEnum.OPC10040005);
}
return mimeMessage;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project books by aidanwhiteley.
the class MailClient method sendEmailsToAdminsForNewUsers.
public boolean sendEmailsToAdminsForNewUsers(List<User> newUsers) {
boolean emailSent = true;
MimeMessagePreparator messagePreparator = mimeMessage -> {
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
messageHelper.setFrom(registrationAdminEmailFrom);
messageHelper.setTo(registrationAdminEmailTo);
messageHelper.setSubject(registrationAdminEmailTitle);
messageHelper.setText(prepareAdminNewUsersNotificationEmailContent(newUsers));
};
try {
mailSender.send(messagePreparator);
} catch (MailException me) {
emailSent = false;
LOGGER.error("Failed to send user registration emails for {}", newUsers, me);
}
return emailSent;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project portal by ixinportal.
the class SendEmailImpl method sendEmailAndPorxy.
private void sendEmailAndPorxy(EmailServer emailServer, String mailContent, String[] toEmail, String subject, boolean isHtml, Map<String, File> porxyMap) throws Exception {
if (emailServer.getIsAuth()) {
props.put("mail.smtp.auth", true);
}
props.put("mail.transport.protocol", "smtp");
mailSender.setJavaMailProperties(props);
mailSender.setUsername(emailServer.getAccountName());
mailSender.setPassword(emailServer.getAccountPasswd());
mailSender.setPort(emailServer.getServerPort());
mailSender.setHost(emailServer.getServerHost());
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, // 防止出现中文乱码,
"UTF-8");
// 设置发送方地址
message.setFrom(emailServer.getAccountName());
// 设置接收方的email地址
message.setTo(toEmail);
// 设置邮件主题
message.setSubject(subject);
message.setText(mailContent, isHtml);
System.out.println(porxyMap);
// 添加附件(授权书)
for (Map.Entry<String, File> entry : porxyMap.entrySet()) {
message.addAttachment(entry.getKey(), entry.getValue());
}
mailSender.send(mimeMessage);
}
Aggregations