use of jakarta.mail.internet.MimeBodyPart in project athenz by yahoo.
the class EmailNotificationService method getMimeMessage.
private MimeMessage getMimeMessage(String subject, String body, Collection<String> recipients, String from, byte[] logoImage) throws MessagingException {
Session session = Session.getDefaultInstance(new Properties());
// Create a new MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Add subject, from and to lines.
message.setSubject(subject, CHARSET_UTF_8);
message.setFrom(new InternetAddress(from));
message.setRecipients(jakarta.mail.Message.RecipientType.BCC, InternetAddress.parse(String.join(",", recipients)));
// Set the HTML part.
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(body, "text/html; charset=" + CHARSET_UTF_8);
// Create a multipart/mixed parent container.
MimeMultipart msgParent = new MimeMultipart("related");
// Add the body to the message.
msgParent.addBodyPart(htmlPart);
// Add the parent container to the message.
message.setContent(msgParent);
if (logoImage != null) {
MimeBodyPart logo = new MimeBodyPart();
logo.setContent(logoImage, "image/png");
logo.setContentID(HTML_LOGO_CID_PLACEHOLDER);
logo.setDisposition(Part.INLINE);
// Add the attachment to the message.
msgParent.addBodyPart(logo);
}
return message;
}
Aggregations