use of org.springframework.mail.javamail.MimeMessageHelper in project Settler by EmhyrVarEmreis.
the class EmailService method sendEmail.
@Async
public void sendEmail(List<String> to, EmailTemplate emailTemplate, Map<String, String> options) {
EmailTemplateTmp emailTemplateTmp = EmailTemplateTmp.from(emailTemplate);
for (Map.Entry<String, String> optionsEntry : options.entrySet()) {
emailTemplateTmp.subject = emailTemplateTmp.subject.replaceAll("\\$" + optionsEntry.getKey(), optionsEntry.getValue());
emailTemplateTmp.content = emailTemplateTmp.content.replaceAll("\\$" + optionsEntry.getKey(), optionsEntry.getValue());
}
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(to.toArray(new String[to.size()]));
message.setFrom(settlerProperties.getMail().getFromAddress());
message.setSubject(emailTemplateTmp.subject);
message.setText(emailTemplateTmp.content, true);
};
try {
mailSender.send(preparator);
} catch (Exception e) {
log.error("Error occurred during sendEmail", e);
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project OpenClinica by OpenClinica.
the class QueryServiceImpl method sendEmail.
private void sendEmail(String to, String subject, String body, Boolean htmlEmail) throws Exception {
try {
JavaMailSenderImpl mailSender = (JavaMailSenderImpl) appContext.getBean("mailSender");
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(EmailEngine.getAdminEmail());
helper.setTo(processMultipleImailAddresses(to.trim()));
helper.setSubject(subject);
helper.setText(body, true);
mailSender.send(mimeMessage);
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
logger.error("Email could not be sent on {} due to: {}", new Date(), me.getMessage());
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project cas by apereo.
the class CommunicationsManager method email.
/**
* Email.
*
* @param text the text
* @param from the from
* @param subject the subject
* @param to the to
* @param cc the cc
* @param bcc the bcc
* @return the boolean
*/
public boolean email(final String text, final String from, final String subject, final String to, final String cc, final String bcc) {
try {
if (!isMailSenderDefined() || StringUtils.isBlank(text) || StringUtils.isBlank(from) || StringUtils.isBlank(subject) || StringUtils.isBlank(to)) {
LOGGER.warn("Could not send email to [{}] because either no address/subject/text is found or email settings are not configured.", to);
return false;
}
final MimeMessage message = this.mailSender.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(to);
helper.setText(text);
helper.setSubject(subject);
helper.setFrom(from);
helper.setPriority(1);
if (StringUtils.isNotBlank(cc)) {
helper.setCc(cc);
}
if (StringUtils.isNotBlank(bcc)) {
helper.setBcc(bcc);
}
this.mailSender.send(message);
return true;
} catch (final Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
return false;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project topcom-cloud by 545314690.
the class EmailUtil method send.
public static void send(EmailVO emailVO) throws MessagingException, UnsupportedEncodingException {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, emailVO.isMultipart(), "utf-8");
mimeMessageHelper.setTo(emailVO.getTo());
mimeMessageHelper.setFrom(EMAIL_FROM, PERSONAL);
mimeMessageHelper.setSubject(emailVO.getSubject());
if (StringUtils.isNotBlank(emailVO.getContent())) {
mimeMessageHelper.setText(emailVO.getContent(), emailVO.isHtml());
}
String[] cc = emailVO.getCc();
if (cc != null && cc.length > 0) {
mimeMessageHelper.setCc(cc);
}
// 发送邮件
mailSender.send(mimeMessage);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project webofneeds by researchstudio-sat.
the class WonMailSender method sendHtmlMessage.
public void sendHtmlMessage(String toEmail, String subject, String htmlBody) {
MimeMessage msg = mailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(msg, true);
helper.setFrom(this.templateMessage.getFrom());
helper.setSubject(subject);
helper.setTo(toEmail);
helper.setText(htmlBody, true);
mailSender.send(msg);
} catch (Exception ex) {
logger.warn(ex.getMessage());
}
}
Aggregations