Search in sources :

Example 1 with EmailPopulatingBuilder

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);
}
Also used : Email(org.simplejavamail.api.email.Email) EmailPopulatingBuilder(org.simplejavamail.api.email.EmailPopulatingBuilder)

Example 2 with EmailPopulatingBuilder

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);
}
Also used : Email(org.simplejavamail.api.email.Email) EmailPopulatingBuilder(org.simplejavamail.api.email.EmailPopulatingBuilder) Recipient(org.simplejavamail.api.email.Recipient) File(java.io.File) Test(org.junit.Test)

Example 3 with EmailPopulatingBuilder

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());
}
Also used : Email(org.simplejavamail.api.email.Email) EmailConverter.mimeMessageToEmail(org.simplejavamail.converter.EmailConverter.mimeMessageToEmail) EmailPopulatingBuilder(org.simplejavamail.api.email.EmailPopulatingBuilder) InternalEmailPopulatingBuilder(org.simplejavamail.email.internal.InternalEmailPopulatingBuilder) File(java.io.File) Test(org.junit.Test)

Example 4 with EmailPopulatingBuilder

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());
}
Also used : Email(org.simplejavamail.api.email.Email) EmailConverter.mimeMessageToEmail(org.simplejavamail.converter.EmailConverter.mimeMessageToEmail) EmailPopulatingBuilder(org.simplejavamail.api.email.EmailPopulatingBuilder) InternalEmailPopulatingBuilder(org.simplejavamail.email.internal.InternalEmailPopulatingBuilder) File(java.io.File) Test(org.junit.Test)

Example 5 with EmailPopulatingBuilder

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());
}
Also used : Email(org.simplejavamail.api.email.Email) EmailConverter.mimeMessageToEmail(org.simplejavamail.converter.EmailConverter.mimeMessageToEmail) EmailPopulatingBuilder(org.simplejavamail.api.email.EmailPopulatingBuilder) InternalEmailPopulatingBuilder(org.simplejavamail.email.internal.InternalEmailPopulatingBuilder) File(java.io.File) Test(org.junit.Test)

Aggregations

EmailPopulatingBuilder (org.simplejavamail.api.email.EmailPopulatingBuilder)29 Test (org.junit.Test)21 Email (org.simplejavamail.api.email.Email)15 File (java.io.File)8 InternalEmailPopulatingBuilder (org.simplejavamail.email.internal.InternalEmailPopulatingBuilder)8 MimeMessage (jakarta.mail.internet.MimeMessage)6 EmailConverter.mimeMessageToEmail (org.simplejavamail.converter.EmailConverter.mimeMessageToEmail)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Recipient (org.simplejavamail.api.email.Recipient)4 ByteArrayDataSource (jakarta.mail.util.ByteArrayDataSource)2 ImmutableDelegatingSMTPMessage (org.simplejavamail.converter.internal.mimemessage.ImmutableDelegatingSMTPMessage)2 EmailStartingBuilderImpl (org.simplejavamail.email.internal.EmailStartingBuilderImpl)2 MailerRegularBuilderImpl (org.simplejavamail.mailer.internal.MailerRegularBuilderImpl)2 MimeMessageAndEnvelope (testutil.testrules.MimeMessageAndEnvelope)2 URL (java.net.URL)1 X509Certificate (java.security.cert.X509Certificate)1 GregorianCalendar (java.util.GregorianCalendar)1 HashedMap (org.apache.commons.collections4.map.HashedMap)1 NotNull (org.jetbrains.annotations.NotNull)1 Property (org.simplejavamail.config.ConfigLoader.Property)1