use of org.simplejavamail.api.email.EmailPopulatingBuilder in project LAPIS by cevo-public.
the class SmtpNotificationSystem method sendReport.
@Override
public void sendReport(SendableReport report) {
EmailPopulatingBuilder builder = EmailBuilder.startingBlank().from(senderAddress).withSubject(report.getSubject()).withPlainText(report.getEmailText());
for (String recipient : recipients) {
builder.to(recipient);
}
if (report.getPriority() == SendableReport.PriorityLevel.FATAL) {
builder.withHeader("X-Priority", 1);
}
Email email = builder.buildEmail();
mailer.sendMail(email);
}
use of org.simplejavamail.api.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class TestSmimeAttachments method testSMIMEMessageFromOutlookMsgWithNonMergingBehavior.
@Test
public void testSMIMEMessageFromOutlookMsgWithNonMergingBehavior() {
Email emailParsedFromMsg = EmailConverter.outlookMsgToEmailBuilder(new File(RESOURCE_FOLDER + "/SMIME (signed and clear text).msg")).notMergingSingleSMIMESignedAttachment().buildEmail();
EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Alessandro Gasparini", "donotreply@unknown-from-address.net", null));
EmailAssert.assertThat(emailParsedFromMsg).hasSubject("Invio messaggio SMIME (signed and clear text)");
EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("a.gasparini@logicaldoc.com", "a.gasparini@logicaldoc.com", TO));
assertThat(emailParsedFromMsg.getHeaders()).isEmpty();
assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isNullOrEmpty();
assertThat(emailParsedFromMsg.getHTMLText()).isNullOrEmpty();
assertThat(emailParsedFromMsg.getEmbeddedImages()).isEmpty();
assertThat(emailParsedFromMsg.getAttachments()).hasSize(1);
assertThat(emailParsedFromMsg.getAttachments()).extracting("name").containsExactly("smime.p7m");
assertThat(emailParsedFromMsg.getDecryptedAttachments()).hasSize(1);
assertThat(emailParsedFromMsg.getDecryptedAttachments()).extracting("name").containsExactly("signed-email.eml");
final Email smimeSignedEmail = verifyNonnullOrEmpty(emailParsedFromMsg.getSmimeSignedEmail());
assertThat(smimeSignedEmail.getHeaders()).contains(new SimpleEntry<>("Message-ID", singletonList(SMIME_ATTACHMENT_MESSAGE_ID)));
assertThat(normalizeNewlines(smimeSignedEmail.getPlainText())).isEqualTo("Invio messaggio SMIME (signed and clear text)\n" + "\n" + "-- \n" + "Alessandro Gasparini\n" + "Chief Technology Officer\n" + "\n" + "\n" + "\n" + "\n" + "LOGICALDOC Srl\n" + "Via Aldo Moro interna 3\n" + "41012 Carpi / Modena\n" + "\n" + "P: +39 059 5970906\n" + " <https://www.logicaldoc.com> https://www.logicaldoc.com \n" + "\n" + " \n" + "\n");
assertThat(smimeSignedEmail.getHTMLText()).contains("<p class=MsoNormal><span lang=EN-US>Invio messaggio SMIME (signed and clear text)<o:p>");
assertThat(smimeSignedEmail.getEmbeddedImages()).isEmpty();
assertThat(smimeSignedEmail.getAttachments()).hasSize(1);
assertThat(smimeSignedEmail.getAttachments()).extracting("name").containsExactly("3 crucial benefits of Cloud computing.docx");
assertThat(smimeSignedEmail.getDecryptedAttachments()).hasSize(1);
assertThat(smimeSignedEmail.getDecryptedAttachments()).extracting("name").containsExactly("3 crucial benefits of Cloud computing.docx");
EmailAssert.assertThat(emailParsedFromMsg).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("application/pkcs7-mime").smimeType("signed-data").smimeName("smime.p7m").smimeSignedBy("shatzing5@outlook.com").smimeSignatureValid(true).build());
// verify msg that was sent with Outlook against eml that was received in Thunderbird
EmailPopulatingBuilder fromEmlBuilder = EmailConverter.emlToEmailBuilder(new File(RESOURCE_FOLDER + "/SMIME (signed and clear text).eml"));
Email emailExpectedFromEml = fromEmlBuilder.clearHeaders().clearReplyTo().clearBounceTo().from(verifyNonnullOrEmpty(fromEmlBuilder.getFromRecipient()).getName(), "donotreply@unknown-from-address.net").buildEmail();
Email emailWithCopiedMerginBehavior = EmailBuilder.ignoringDefaults().copying(emailParsedFromMsg).buildEmail();
EmailAssert.assertThat(emailWithCopiedMerginBehavior).isEqualTo(emailParsedFromMsg);
Email emailWithDefaultMerginBehavior = EmailBuilder.ignoringDefaults().copying(emailParsedFromMsg).clearSMIMESignedAttachmentMergingBehavior().buildEmail();
EmailAssert.assertThat(emailWithDefaultMerginBehavior).isEqualTo(emailExpectedFromEml);
}
use of org.simplejavamail.api.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageDefaultSmimeSignTest.
@Test
public void createMailSession_OutlookMessageDefaultSmimeSignTest() throws IOException, MessagingException, ExecutionException, InterruptedException {
// override the default from the @Before test
mailer = MailerBuilder.withSMTPServer("localhost", SERVER_PORT).signByDefaultWithSmime(new File(RESOURCES_PKCS + "/smime_keystore.pkcs12"), "letmein", "smime_test_user_alias", "letmein").buildMailer();
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
Email email = assertSendingEmail(builder, false, true, false, true, false);
// verify that S/MIME was indeed only configured on the mailer instance
assertThat(mailer.getEmailGovernance().getPkcs12ConfigForSmimeSigning()).isNotNull();
assertThat(builder.getPkcs12ConfigForSmimeSigning()).isNull();
assertThat(email.getPkcs12ConfigForSmimeSigning()).isNull();
verifyReceivedOutlookEmail(email, true, false);
EmailAssert.assertThat(email).wasNotMergedWithSmimeSignedMessage();
EmailAssert.assertThat(email).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-256").smimeSignedBy("Benny Bottema").smimeSignatureValid(true).build());
}
use of org.simplejavamail.api.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageSmimeSignTest.
@Test
public void createMailSession_OutlookMessageSmimeSignTest() throws IOException, MessagingException, ExecutionException, InterruptedException {
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
builder.signWithSmime(new File(RESOURCES_PKCS + "/smime_keystore.pkcs12"), "letmein", "smime_test_user_alias", "letmein");
Email email = assertSendingEmail(builder, false, true, false, true, false);
verifyReceivedOutlookEmail(email, true, false);
EmailAssert.assertThat(email).wasNotMergedWithSmimeSignedMessage();
EmailAssert.assertThat(email).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-256").smimeSignedBy("Benny Bottema").smimeSignatureValid(true).build());
}
use of org.simplejavamail.api.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageSmimeEncryptTest.
@Test
public void createMailSession_OutlookMessageSmimeEncryptTest() throws IOException, MessagingException, ExecutionException, InterruptedException {
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
builder.encryptWithSmime(new File(RESOURCES_PKCS + "/smime_test_user.pem.standard.crt"));
Email email = assertSendingEmail(builder, false, true, false, true, false);
verifyReceivedOutlookEmail(email, false, true);
EmailAssert.assertThat(email).wasMergedWithSmimeSignedMessage();
EmailAssert.assertThat(email).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.ENCRYPTED).smimeMime("application/pkcs7-mime").smimeType("enveloped-data").smimeName("smime.p7m").build());
}
Aggregations