use of org.springframework.mail.javamail.MimeMessageHelper in project scoold by Erudika.
the class ScooldEmailer method sendEmail.
@Override
public boolean sendEmail(final List<String> emails, final String subject, final String body) {
if (emails == null || emails.isEmpty()) {
return false;
}
asyncExecute(() -> {
emails.forEach(email -> {
try {
mailSender.send((MimeMessage mimeMessage) -> {
MimeMessageHelper msg = new MimeMessageHelper(mimeMessage);
msg.setTo(email);
msg.setSubject(subject);
msg.setFrom(Config.SUPPORT_EMAIL, Config.APP_NAME);
// body is assumed to be HTML
msg.setText(body, true);
});
logger.debug("Email sent to {}, {}", email, subject);
} catch (MailException ex) {
logger.error("Failed to send email to {} with body [{}]. {}", email, body, ex.getMessage());
}
});
});
return true;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project OpenClinica by OpenClinica.
the class NotificationActionProcessor method createMimeMessagePreparator.
private void createMimeMessagePreparator(final ParticipantDTO pDTO, final String email) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setFrom(EmailEngine.getAdminEmail());
message.setTo(email);
message.setSubject(pDTO.getEmailSubject());
message.setText(pDTO.getMessage());
}
};
BulkEmailSenderService.addMimeMessage(preparator);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project OpenClinica by OpenClinica.
the class CoreSecureController method sendEmail.
public Boolean sendEmail(String to, String from, String subject, String body, Boolean htmlEmail, String successMessage, String failMessage, Boolean sendMessage, HttpServletRequest request) throws Exception {
Boolean messageSent = true;
try {
JavaMailSenderImpl mailSender = (JavaMailSenderImpl) SpringServletAccess.getApplicationContext(getServletContext()).getBean("mailSender");
// @pgawade 09-Feb-2012 #issue 13201 - setting the "mail.smtp.localhost" property to localhost when java API is not able to
// retrieve the host name
Properties javaMailProperties = mailSender.getJavaMailProperties();
if (null != javaMailProperties) {
if (javaMailProperties.get("mail.smtp.localhost") == null || ((String) javaMailProperties.get("mail.smtp.localhost")).equalsIgnoreCase("")) {
javaMailProperties.put("mail.smtp.localhost", "localhost");
}
}
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, htmlEmail);
helper.setFrom(from);
helper.setTo(processMultipleImailAddresses(to.trim()));
helper.setSubject(subject);
helper.setText(body, true);
mailSender.send(mimeMessage);
if (successMessage != null && sendMessage) {
addPageMessage(successMessage, request);
}
LOGGER.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
me.printStackTrace();
if (failMessage != null && sendMessage) {
addPageMessage(failMessage, request);
}
LOGGER.debug("Email could not be sent on {} due to: {}", new Date(), me.toString());
messageSent = false;
}
return messageSent;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project zhcet-web by zhcet-amu.
the class EmailService method constructHtmlEmail.
private MimeMessage constructHtmlEmail(String emailAddress, String subject, String body, String[] bcc) throws MessagingException {
MimeMessage mimeMessage = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
helper.setText(body, true);
setBasicInfo(helper, senderEmail, emailAddress, subject, bcc);
return mimeMessage;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project xmall by Exrick.
the class EmailUtil method sendEmailPayResult.
@Async
public void sendEmailPayResult(String sendTo, String title, String content) {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设定邮箱服务器配置
senderImpl.setHost(EMAIL_HOST);
senderImpl.setUsername(EMAIL_USERNAME);
senderImpl.setPassword(EMAIL_PASSWORD);
Properties prop = new Properties();
// 服务器进行认证
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.timeout", "20000");
// qq邮箱需开启
prop.put("mail.smtp.ssl.enable", "true");
// 邮箱发送服务器端口,这里设置为465端口 避免服务器解封25端口
prop.setProperty("mail.smtp.port", "465");
prop.setProperty("mail.smtp.socketFactory.port", "465");
prop.put("mail.smtp.auth", "true");
senderImpl.setJavaMailProperties(prop);
// 发送html邮件
MimeMessage mailMessage = senderImpl.createMimeMessage();
MimeMessageHelper messageHelper = null;
// 设置邮件内容
try {
messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8");
messageHelper.setTo(sendTo);
messageHelper.setFrom(EMAIL_SENDER);
messageHelper.setSubject(title);
// true表示HTML格式的邮件
messageHelper.setText(content, true);
} catch (MessagingException e) {
e.printStackTrace();
}
// 发送邮件
senderImpl.send(mailMessage);
log.info("给 " + sendTo + " 的审核结果邮件发送成功");
}
Aggregations