use of org.springframework.mail.javamail.MimeMessageHelper in project thingsboard by thingsboard.
the class MailPlugin method sendMail.
private void sendMail(SendMailActionMsg msg) throws MessagingException {
log.debug("Sending mail {}", msg);
MimeMessage mailMsg = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mailMsg, "UTF-8");
helper.setFrom(msg.getFrom());
helper.setTo(msg.getTo().split("\\s*,\\s*"));
if (!StringUtils.isEmpty(msg.getCc())) {
helper.setCc(msg.getCc().split("\\s*,\\s*"));
}
if (!StringUtils.isEmpty(msg.getBcc())) {
helper.setBcc(msg.getBcc().split("\\s*,\\s*"));
}
helper.setSubject(msg.getSubject());
helper.setText(msg.getBody());
mailSender.send(helper.getMimeMessage());
log.debug("Mail sent {}", msg);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project netxms by netxms.
the class SmtpSenderImpl method mail.
@Override
public void mail(String to, String subject, String body, String fileName, File file) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
if (fileName != null && file != null) {
helper.addAttachment(fileName, file);
}
helper.setText(body);
mailSender.send(message);
} catch (MessagingException e) {
log.error("Unable to send notification mail", e);
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project commons by craftercms.
the class EmailFactoryImpl method createMessage.
protected MimeMessage createMessage(String from, String[] to, String[] cc, String[] bcc, String replyTo, String subject, String body, boolean html, File... attachments) throws EmailException {
boolean addAttachments = ArrayUtils.isNotEmpty(attachments);
MimeMessageHelper messageHelper;
try {
if (addAttachments) {
messageHelper = new MimeMessageHelper(mailSender.createMimeMessage(), true);
} else {
messageHelper = new MimeMessageHelper(mailSender.createMimeMessage());
}
messageHelper.setFrom(from);
if (to != null) {
messageHelper.setTo(to);
}
if (cc != null) {
messageHelper.setCc(cc);
}
if (bcc != null) {
messageHelper.setBcc(bcc);
}
if (replyTo != null) {
messageHelper.setReplyTo(replyTo);
}
messageHelper.setSubject(subject);
messageHelper.setText(body, html);
if (addAttachments) {
for (File attachment : attachments) {
messageHelper.addAttachment(attachment.getName(), attachment);
}
}
} catch (AddressException e) {
throw new EmailAddressException(e);
} catch (MessagingException e) {
throw new EmailPreparationException(e);
}
logger.debug(LOG_KEY_MIME_MSG_CREATED, from, StringUtils.join(to, ','), StringUtils.join(cc, ','), StringUtils.join(bcc, ','), subject, body);
return messageHelper.getMimeMessage();
}
use of org.springframework.mail.javamail.MimeMessageHelper in project spring-boot-admin by codecentric.
the class MailNotifier method doNotify.
@Override
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
return Mono.fromRunnable(() -> {
Context ctx = new Context();
ctx.setVariables(additionalProperties);
ctx.setVariable("baseUrl", this.baseUrl);
ctx.setVariable("event", event);
ctx.setVariable("instance", instance);
ctx.setVariable("lastStatus", getLastStatus(event.getInstance()));
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, StandardCharsets.UTF_8.name());
message.setText(getBody(ctx).replaceAll("\\s+\\n", "\n"), true);
message.setSubject(getSubject(ctx));
message.setTo(this.to);
message.setCc(this.cc);
message.setFrom(this.from);
mailSender.send(mimeMessage);
} catch (MessagingException ex) {
throw new RuntimeException("Error sending mail notification", ex);
}
});
}
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);
}
}
Aggregations