Search in sources :

Example 1 with Recipient

use of org.simplejavamail.api.email.Recipient in project nzyme by lennartkoopmann.

the class LeaderConfigurationLoader method parseReporting.

private ReportingConfiguration parseReporting() {
    if (root.hasPath(ConfigurationKeys.REPORTING)) {
        Config c = root.getConfig(ConfigurationKeys.REPORTING);
        ReportingConfiguration.Email email;
        if (c.hasPath(ConfigurationKeys.EMAIL)) {
            Config e = c.getConfig(ConfigurationKeys.EMAIL);
            // "Recipient" as FROM is library weirdness.
            Recipient from;
            try {
                from = Tools.parseEmailAddress(e.getString(ConfigurationKeys.FROM));
            } catch (InvalidConfigurationException ex) {
                // This is checked during validation and *should* not happen.
                throw new RuntimeException("Invalid email address format.", ex);
            }
            email = ReportingConfiguration.Email.create(TransportStrategy.valueOf(e.getString(ConfigurationKeys.TRANSPORT_STRATEGY)), e.getString(ConfigurationKeys.HOST), e.getInt(ConfigurationKeys.PORT), e.getString(ConfigurationKeys.USERNAME), e.getString(ConfigurationKeys.PASSWORD), from, e.getString(ConfigurationKeys.SUBJECT_PREFIX));
        } else {
            email = null;
        }
        return ReportingConfiguration.create(email);
    } else {
        return null;
    }
}
Also used : Config(com.typesafe.config.Config) Recipient(org.simplejavamail.api.email.Recipient)

Example 2 with Recipient

use of org.simplejavamail.api.email.Recipient in project nzyme by lennartkoopmann.

the class EmailCallback method parseConfiguration.

public static Configuration parseConfiguration(Config c, String httpExternalUri) throws InvalidConfigurationException, IncompleteConfigurationException {
    // Completeness.
    ConfigurationValidator.expect(c, ConfigurationKeys.TRANSPORT_STRATEGY, WHERE, String.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.HOST, WHERE, String.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.PORT, WHERE, Integer.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.USERNAME, WHERE, String.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.PASSWORD, WHERE, String.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.RECIPIENTS, WHERE, List.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.FROM, WHERE, String.class);
    ConfigurationValidator.expect(c, ConfigurationKeys.SUBJECT_PREFIX, WHERE, String.class);
    // Validity.
    // Transport strategy exists.
    TransportStrategy transportStrategy;
    try {
        transportStrategy = TransportStrategy.valueOf(c.getString(ConfigurationKeys.TRANSPORT_STRATEGY));
    } catch (IllegalArgumentException e) {
        throw new InvalidConfigurationException("Invalid SMTP transport strategy.", e);
    }
    // Recipients are valid.
    List<Recipient> recipients = Lists.newArrayList();
    for (String rec : c.getStringList(ConfigurationKeys.RECIPIENTS)) {
        recipients.add(Tools.parseEmailAddress(rec));
    }
    return Configuration.create(transportStrategy, c.getString(ConfigurationKeys.HOST), c.getInt(ConfigurationKeys.PORT), c.getString(ConfigurationKeys.USERNAME), c.getString(ConfigurationKeys.PASSWORD), recipients, // recipient type is ignored
    Tools.parseEmailAddress(c.getString(ConfigurationKeys.FROM)), c.getString(ConfigurationKeys.SUBJECT_PREFIX), httpExternalUri);
}
Also used : Recipient(org.simplejavamail.api.email.Recipient) TransportStrategy(org.simplejavamail.api.mailer.config.TransportStrategy) InvalidConfigurationException(horse.wtf.nzyme.configuration.InvalidConfigurationException)

Example 3 with Recipient

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

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

the class TestSmimeSelfSigned method testEncryptedMessageMsg.

@Test
public void testEncryptedMessageMsg() {
    Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message encrypted.msg"), loadPkcs12KeyStore());
    EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null));
    EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message 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.EDA02623.55A510EE@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(2);
    assertThat(emailParsedFromMsg.getAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7m", "03-07-2005 errata SharnErrata.pdf");
    assertThat(emailParsedFromMsg.getDecryptedAttachments()).hasSize(2);
    assertThat(emailParsedFromMsg.getDecryptedAttachments()).extracting("name").containsExactlyInAnyOrder("signed-email.eml", "03-07-2005 errata SharnErrata.pdf");
    EmailAssert.assertThat(emailParsedFromMsg).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.ENCRYPTED).smimeMime("application/pkcs7-mime").smimeType("enveloped-data").smimeName("smime.p7m").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 5 with Recipient

use of org.simplejavamail.api.email.Recipient 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)

Aggregations

Recipient (org.simplejavamail.api.email.Recipient)56 Test (org.junit.Test)43 Email (org.simplejavamail.api.email.Email)31 File (java.io.File)10 AttachmentResource (org.simplejavamail.api.email.AttachmentResource)7 InternetAddress (jakarta.mail.internet.InternetAddress)4 NotNull (org.jetbrains.annotations.NotNull)4 EmailPopulatingBuilder (org.simplejavamail.api.email.EmailPopulatingBuilder)4 EmailConverter.mimeMessageToEmail (org.simplejavamail.converter.EmailConverter.mimeMessageToEmail)4 Address (jakarta.mail.Address)2 MimeMessage (jakarta.mail.internet.MimeMessage)2 InputStream (java.io.InputStream)2 Collection (java.util.Collection)2 Map (java.util.Map)2 HashedMap (org.apache.commons.collections4.map.HashedMap)2 Property (org.simplejavamail.config.ConfigLoader.Property)2 InternalEmailPopulatingBuilder (org.simplejavamail.email.internal.InternalEmailPopulatingBuilder)2 Test (org.testng.annotations.Test)2 EmailHelper (testutil.EmailHelper)2 MimeMessageAndEnvelope (testutil.testrules.MimeMessageAndEnvelope)2