Search in sources :

Example 11 with Email

use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.

the class TestSmimeSelfSigned method testSignedAndEncryptedMessageMsg.

@Test
public void testSignedAndEncryptedMessageMsg() {
    Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed & encrypted.msg"), loadPkcs12KeyStore());
    EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null));
    EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message signed & encrypted");
    EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO));
    assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" + "\n" + "For testing purposes in the Simple Java Mail project.\n" + "\n");
    assertThat(emailParsedFromMsg.getEmbeddedImages()).hasSize(1);
    AttachmentResource embeddedImg = emailParsedFromMsg.getEmbeddedImages().get(0);
    assertThat(embeddedImg.getName()).isEqualTo("part1.0B245DA7.F5872CD5@bennybottema.com");
    assertThat(embeddedImg.getDataSource().getName()).isEqualTo("module_architecture.png");
    assertThat(embeddedImg.getDataSource().getContentType()).isEqualTo("image/png");
    assertThat(emailParsedFromMsg.getHTMLText()).contains(format("<img src=\"cid:%s\"", embeddedImg.getName()));
    assertThat(emailParsedFromMsg.getAttachments()).hasSize(3);
    assertThat(emailParsedFromMsg.getAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7m", "smime.p7s", "03-07-2005 errata SharnErrata.pdf");
    assertThat(emailParsedFromMsg.getDecryptedAttachments()).hasSize(3);
    assertThat(emailParsedFromMsg.getDecryptedAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7s", "signed-email.eml", "03-07-2005 errata SharnErrata.pdf");
    EmailAssert.assertThat(emailParsedFromMsg).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED_ENCRYPTED).smimeMime("application/pkcs7-mime").smimeType("enveloped-data").smimeName("smime.p7m").build());
    EmailAssert.assertThat(emailParsedFromMsg.getSmimeSignedEmail()).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-512").smimeSignatureValid(true).smimeSignedBy("Benny Bottema").build());
}
Also used : AttachmentResource(org.simplejavamail.api.email.AttachmentResource) Email(org.simplejavamail.api.email.Email) Recipient(org.simplejavamail.api.email.Recipient) File(java.io.File) Test(org.junit.Test)

Example 12 with Email

use of org.simplejavamail.api.email.Email 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 13 with Email

use of org.simplejavamail.api.email.Email 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 14 with Email

use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.

the class MailerLiveTest method createMailSession_OutlookMessageTest.

@Test
public void createMailSession_OutlookMessageTest() throws IOException, MessagingException, ExecutionException, InterruptedException {
    Email email = assertSendingEmail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg"), false, false, false, true, false);
    verifyReceivedOutlookEmail(email, false, false);
}
Also used : Email(org.simplejavamail.api.email.Email) EmailConverter.mimeMessageToEmail(org.simplejavamail.converter.EmailConverter.mimeMessageToEmail) Test(org.junit.Test)

Example 15 with Email

use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.

the class MailerLiveTest method testOutlookMessageWithNestedOutlookMessageAttachment.

@Test
public void testOutlookMessageWithNestedOutlookMessageAttachment() {
    InputStream resourceAsStream = EmailHelper.class.getClassLoader().getResourceAsStream("test-messages/#298 Email with nested msg.msg");
    Email email = EmailConverter.outlookMsgToEmail(checkNonEmptyArgument(resourceAsStream, "resourceAsStream"));
    assertThat(email.getAttachments()).hasSize(2);
    assertThat(email.getAttachments().get(1).getName()).isEqualTo("This msg file is an attachment.eml");
    final InputStream emlInputstream = email.getAttachments().get(1).getDataSourceInputStream();
    Email nestedEmail = EmailConverter.emlToEmail(emlInputstream);
    EmailAssert.assertThat(nestedEmail).hasSubject("This msg file is an attachment");
    assertThat(normalizeNewlines(nestedEmail.getPlainText())).isEqualTo("This is an email that will be attached to another email.\n");
    EmailAssert.assertThat(nestedEmail).hasOnlyRecipients(new Recipient("atmcquillen@gmail.com", "atmcquillen@gmail.com", TO));
}
Also used : Email(org.simplejavamail.api.email.Email) EmailConverter.mimeMessageToEmail(org.simplejavamail.converter.EmailConverter.mimeMessageToEmail) InputStream(java.io.InputStream) EmailHelper(testutil.EmailHelper) Recipient(org.simplejavamail.api.email.Recipient) Test(org.junit.Test)

Aggregations

Email (org.simplejavamail.api.email.Email)121 Test (org.junit.Test)101 Recipient (org.simplejavamail.api.email.Recipient)31 File (java.io.File)26 EmailPopulatingBuilder (org.simplejavamail.api.email.EmailPopulatingBuilder)15 MimeMessage (jakarta.mail.internet.MimeMessage)10 EmailConverter.mimeMessageToEmail (org.simplejavamail.converter.EmailConverter.mimeMessageToEmail)10 InternalEmailPopulatingBuilder (org.simplejavamail.email.internal.InternalEmailPopulatingBuilder)7 URL (java.net.URL)6 AttachmentResource (org.simplejavamail.api.email.AttachmentResource)6 ByteArrayDataSource (jakarta.mail.util.ByteArrayDataSource)5 InternetAddress (jakarta.mail.internet.InternetAddress)4 Date (java.util.Date)4 SpEmail (org.apache.streampipes.model.mail.SpEmail)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 GregorianCalendar (java.util.GregorianCalendar)3 HashedMap (org.apache.commons.collections4.map.HashedMap)3 NotNull (org.jetbrains.annotations.NotNull)3 MimeMessageAndEnvelope (testutil.testrules.MimeMessageAndEnvelope)3 IOException (java.io.IOException)2