use of org.springframework.mail.javamail.MimeMessagePreparator in project BroadleafCommerce by BroadleafCommerce.
the class LoggingMailSender method send.
@Override
public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException {
for (MimeMessagePreparator preparator : mimeMessagePreparators) {
try {
MimeMessage mimeMessage = createMimeMessage();
preparator.prepare(mimeMessage);
LOG.info("\"Sending\" email: ");
if (mimeMessage.getContent() instanceof MimeMultipart) {
MimeMultipart msg = (MimeMultipart) mimeMessage.getContent();
DataHandler dh = msg.getBodyPart(0).getDataHandler();
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
dh.writeTo(baos);
} catch (Exception e) {
// Do nothing
} finally {
try {
baos.close();
} catch (Exception e) {
LOG.error("Couldn't close byte array output stream");
}
}
} else {
LOG.info(mimeMessage.getContent());
}
} catch (Exception e) {
LOG.error("Could not create message", e);
}
}
}
use of org.springframework.mail.javamail.MimeMessagePreparator in project OpenClinica by OpenClinica.
the class BulkEmailSenderService method sendEmail.
@Scheduled(fixedDelay = 120000)
private void sendEmail() {
ArrayList<MimeMessagePreparator> mimeMessages = new ArrayList<MimeMessagePreparator>();
logger.info("Executing now..." + mimeMessages.size() + " " + Thread.currentThread().getName() + " " + DEQUE.size());
MimeMessagePreparator mimeMessage = DEQUE.pollFirst();
if (mimeMessage == null) {
logger.info("Nothing left to do getting out...");
return;
}
while (mimeMessage != null) {
mimeMessages.add(mimeMessage);
logger.info("In while loop");
if (mimeMessages.size() == 25) {
logger.info("I've reached my limit...");
break;
} else {
logger.info("Else");
mimeMessage = DEQUE.pollFirst();
}
}
logger.info("Sending Boom email..." + mimeMessages.size());
mailSender.send(mimeMessages.toArray(new MimeMessagePreparator[mimeMessages.size()]));
logger.info("I think i sent my mail..." + mimeMessages.size());
sendEmail();
}
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) {
if (this.mailSender == null) {
LOG.warn("Not sending email. No mailer provided.");
return;
}
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);
}
Aggregations