Search in sources :

Example 1 with MimeMessageBuilder

use of org.apache.logging.log4j.core.net.MimeMessageBuilder in project logging-log4j2 by apache.

the class SmtpAppenderTest method testMessageFactorySetFrom.

@Test
public void testMessageFactorySetFrom() throws MessagingException {
    final MimeMessageBuilder builder = new MimeMessageBuilder(null);
    final String address = "testing@example.com";
    assertNull(builder.build().getFrom());
    builder.setFrom(null);
    Address[] array = null;
    final Address addr = InternetAddress.getLocalAddress(null);
    if (addr != null) {
        array = new Address[] { addr };
    }
    assertArrayEquals(array, builder.build().getFrom());
    builder.setFrom(address);
    assertArrayEquals(new Address[] { new InternetAddress(address) }, builder.build().getFrom());
}
Also used : MimeMessageBuilder(org.apache.logging.log4j.core.net.MimeMessageBuilder) InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) Test(org.junit.Test)

Example 2 with MimeMessageBuilder

use of org.apache.logging.log4j.core.net.MimeMessageBuilder in project logging-log4j2 by apache.

the class SmtpAppenderTest method testMessageFactorySetReplyTo.

@Test
public void testMessageFactorySetReplyTo() throws MessagingException {
    final MimeMessageBuilder builder = new MimeMessageBuilder(null);
    final String addresses = "testing1@example.com,testing2@example.com";
    assertNull(builder.build().getReplyTo());
    builder.setReplyTo(null);
    assertNull(builder.build().getReplyTo());
    builder.setReplyTo(addresses);
    assertArrayEquals(InternetAddress.parse(addresses), builder.build().getReplyTo());
}
Also used : MimeMessageBuilder(org.apache.logging.log4j.core.net.MimeMessageBuilder) Test(org.junit.Test)

Example 3 with MimeMessageBuilder

use of org.apache.logging.log4j.core.net.MimeMessageBuilder in project logging-log4j2 by apache.

the class SmtpAppenderTest method testMessageFactorySetSubject.

@Test
public void testMessageFactorySetSubject() throws MessagingException {
    final MimeMessageBuilder builder = new MimeMessageBuilder(null);
    final String subject = "Test Subject";
    assertNull(builder.build().getSubject());
    builder.setSubject(null);
    assertNull(builder.build().getSubject());
    builder.setSubject(subject);
    assertEquals(subject, builder.build().getSubject());
}
Also used : MimeMessageBuilder(org.apache.logging.log4j.core.net.MimeMessageBuilder) Test(org.junit.Test)

Example 4 with MimeMessageBuilder

use of org.apache.logging.log4j.core.net.MimeMessageBuilder in project logging-log4j2 by apache.

the class SmtpAppenderTest method testMessageFactorySetRecipients.

@Test
public void testMessageFactorySetRecipients() throws MessagingException {
    final MimeMessageBuilder builder = new MimeMessageBuilder(null);
    final String addresses = "testing1@example.com,testing2@example.com";
    assertNull(builder.build().getRecipients(Message.RecipientType.TO));
    builder.setRecipients(Message.RecipientType.TO, null);
    assertNull(builder.build().getRecipients(Message.RecipientType.TO));
    builder.setRecipients(Message.RecipientType.TO, addresses);
    assertArrayEquals(InternetAddress.parse(addresses), builder.build().getRecipients(Message.RecipientType.TO));
}
Also used : MimeMessageBuilder(org.apache.logging.log4j.core.net.MimeMessageBuilder) Test(org.junit.Test)

Aggregations

MimeMessageBuilder (org.apache.logging.log4j.core.net.MimeMessageBuilder)4 Test (org.junit.Test)4 Address (javax.mail.Address)1 InternetAddress (javax.mail.internet.InternetAddress)1