use of org.springframework.mail.javamail.MimeMessagePreparator 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.MimeMessagePreparator 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.MimeMessagePreparator 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.MimeMessagePreparator 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.MimeMessagePreparator in project ma-core-public by infiniteautomation.
the class EmailSender method createPreparator.
public MimeMessagePreparator createPreparator(final InternetAddress from, final InternetAddress replyTo, final InternetAddress[] to, final InternetAddress[] cc, final InternetAddress[] bcc, final String subject, final EmailContent content) throws MailException {
return new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, content.isMultipart(), content.getEncoding());
helper.setFrom(from);
if (replyTo != null)
helper.setReplyTo(replyTo);
helper.setTo(to);
if (cc != null)
helper.setCc(cc);
if (bcc != null)
helper.setBcc(bcc);
// Ensure that line breaks in the subject are removed.
String sub;
if (subject == null)
sub = "";
else {
sub = subject.replaceAll("\\r", "");
sub = sub.replaceAll("\\n", "");
}
helper.setSubject(sub);
if (content.getHtmlContent() == null)
helper.setText(content.getPlainContent(), false);
else if (content.getPlainContent() == null)
helper.setText(content.getHtmlContent(), true);
else
helper.setText(content.getPlainContent(), content.getHtmlContent());
for (EmailAttachment att : content.getAttachments()) att.attach(helper);
for (EmailInline inline : content.getInlines()) inline.attach(helper);
}
};
}
Aggregations