use of jakarta.mail.Session 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;
}
use of jakarta.mail.Session in project spring-boot by spring-projects.
the class MailSenderAutoConfigurationTests method jndiSessionAvailableWithResourceRef.
@Test
void jndiSessionAvailableWithResourceRef() {
Session session = configureJndiSession("java:comp/env/foo");
testJndiSessionLookup(session, "foo");
}
use of jakarta.mail.Session in project spring-boot by spring-projects.
the class MailSenderAutoConfigurationTests method jndiSessionAvailable.
@Test
void jndiSessionAvailable() {
Session session = configureJndiSession("java:comp/env/foo");
testJndiSessionLookup(session, "java:comp/env/foo");
}
use of jakarta.mail.Session in project spring-boot by spring-projects.
the class MailSenderAutoConfigurationTests method jndiSessionTakesPrecedenceOverProperties.
@Test
void jndiSessionTakesPrecedenceOverProperties() {
Session session = configureJndiSession("foo");
this.contextRunner.withPropertyValues("spring.mail.jndi-name:foo", "spring.mail.host:localhost").run((context) -> {
assertThat(context).hasSingleBean(Session.class);
Session sessionBean = context.getBean(Session.class);
assertThat(sessionBean).isEqualTo(session);
assertThat(context.getBean(JavaMailSenderImpl.class).getSession()).isEqualTo(sessionBean);
});
}
use of jakarta.mail.Session in project spring-boot by spring-projects.
the class MailSenderAutoConfigurationTests method testJndiSessionLookup.
private void testJndiSessionLookup(Session session, String jndiName) {
this.contextRunner.withPropertyValues("spring.mail.jndi-name:" + jndiName).run((context) -> {
assertThat(context).hasSingleBean(Session.class);
Session sessionBean = context.getBean(Session.class);
assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
assertThat(sessionBean).isEqualTo(session);
assertThat(context.getBean(JavaMailSenderImpl.class).getSession()).isEqualTo(sessionBean);
});
}
Aggregations