Search in sources :

Example 26 with MailMessageImpl

use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.

the class InternetAddressTest method invalidDeliveryReceipt.

@Test(expected = InvalidAddressException.class)
public void invalidDeliveryReceipt() {
    MailMessage m = new MailMessageImpl(TestMailConfigs.standardConfig());
    m.deliveryReceipt("woo foo @bar.com");
}
Also used : MailMessage(com.outjected.email.api.MailMessage) MailMessageImpl(com.outjected.email.impl.MailMessageImpl) Test(org.junit.Test)

Example 27 with MailMessageImpl

use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.

the class InternetAddressTest method invalidToSimpleAddresses.

@Test(expected = InvalidAddressException.class)
public void invalidToSimpleAddresses() {
    MailMessage m = new MailMessageImpl(TestMailConfigs.standardConfig());
    m.to("woo foo @bar.com");
}
Also used : MailMessage(com.outjected.email.api.MailMessage) MailMessageImpl(com.outjected.email.impl.MailMessageImpl) Test(org.junit.Test)

Example 28 with MailMessageImpl

use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.

the class InternetAddressTest method invalidBccSimpleAddresses.

@Test(expected = InvalidAddressException.class)
public void invalidBccSimpleAddresses() {
    MailMessage m = new MailMessageImpl(TestMailConfigs.standardConfig());
    m.bcc("woo foo @bar.com");
}
Also used : MailMessage(com.outjected.email.api.MailMessage) MailMessageImpl(com.outjected.email.impl.MailMessageImpl) Test(org.junit.Test)

Example 29 with MailMessageImpl

use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.

the class MailMessageTest method testTextMailMessageUsingPerson.

@Test
public void testTextMailMessageUsingPerson() throws MessagingException, IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    String subject = "Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
    Person person = new Person(toName, toAddress);
    String messageId = "1234@seam.test.com";
    EmailMessage e;
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.setHostname(mailConfig.getServerHost());
    try {
        wiser.start();
        e = new MailMessageImpl(mailConfig).from(MailTestUtil.getAddressHeader(fromName, fromAddress)).replyTo(replyToAddress).to(person).subject(subject).bodyText(textBody).importance(MessagePriority.HIGH).messageId(messageId).send();
    } finally {
        stop(wiser);
    }
    Assert.assertTrue("Didn't receive the expected amount of messages. Expected 1 got " + wiser.getMessages().size(), wiser.getMessages().size() == 1);
    MimeMessage mess = wiser.getMessages().get(0).getMimeMessage();
    Assert.assertEquals(MailTestUtil.getAddressHeader(fromName, fromAddress), mess.getHeader("From", null));
    Assert.assertEquals(MailTestUtil.getAddressHeader(replyToAddress), mess.getHeader("Reply-To", null));
    Assert.assertEquals(MailTestUtil.getAddressHeader(toName, toAddress), mess.getHeader("To", null));
    Assert.assertEquals("Subject has been modified", subject, MimeUtility.unfold(mess.getHeader("Subject", null)));
    Assert.assertEquals(MessagePriority.HIGH.getPriority(), mess.getHeader("Priority", null));
    Assert.assertEquals(MessagePriority.HIGH.getX_priority(), mess.getHeader("X-Priority", null));
    Assert.assertEquals(MessagePriority.HIGH.getImportance(), mess.getHeader("Importance", null));
    Assert.assertTrue(mess.getHeader("Content-Type", null).startsWith("multipart/mixed"));
    Assert.assertEquals(messageId, MailUtility.headerStripper(mess.getHeader("Message-ID", null)));
    MimeMultipart mixed = (MimeMultipart) mess.getContent();
    BodyPart text = mixed.getBodyPart(0);
    Assert.assertTrue(mixed.getContentType().startsWith("multipart/mixed"));
    Assert.assertEquals(1, mixed.getCount());
    Assert.assertTrue("Incorrect Charset: " + e.getCharset(), text.getContentType().startsWith("text/plain; charset=" + e.getCharset()));
    Assert.assertEquals(textBody, MailTestUtil.getStringContent(text));
    EmailMessage convertedMessage = MessageConverter.convert(mess);
    Assert.assertEquals(convertedMessage.getSubject(), subject);
}
Also used : MailMessageImpl(com.outjected.email.impl.MailMessageImpl) BodyPart(javax.mail.BodyPart) EmailMessage(com.outjected.email.api.EmailMessage) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) SessionConfig(com.outjected.email.api.SessionConfig) Test(org.junit.Test)

Example 30 with MailMessageImpl

use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.

the class MailMessageTest method testTextMailMessageSpecialCharacters.

@Test
public void testTextMailMessageSpecialCharacters() throws MessagingException, IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    String subject = "Sometimes subjects have speical characters like ü - " + java.util.UUID.randomUUID().toString();
    String specialTextBody = "This is a Text Body with a special character - ü";
    EmailMessage e;
    String messageId = "1234@seam.test.com";
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.setHostname(mailConfig.getServerHost());
    try {
        wiser.start();
        e = new MailMessageImpl(mailConfig).from(MailTestUtil.getAddressHeader(fromName, fromAddress)).replyTo(replyToAddress).to(MailTestUtil.getAddressHeader(toName, toAddress)).subject(subject).bodyText(specialTextBody).importance(MessagePriority.HIGH).messageId(messageId).send();
    } finally {
        stop(wiser);
    }
    Assert.assertTrue("Didn't receive the expected amount of messages. Expected 1 got " + wiser.getMessages().size(), wiser.getMessages().size() == 1);
    MimeMessage mess = wiser.getMessages().get(0).getMimeMessage();
    Assert.assertEquals("Subject has been modified", subject, MimeUtility.decodeText(MimeUtility.unfold(mess.getHeader("Subject", null))));
    MimeMultipart mixed = (MimeMultipart) mess.getContent();
    BodyPart text = mixed.getBodyPart(0);
    Assert.assertTrue(mixed.getContentType().startsWith("multipart/mixed"));
    Assert.assertEquals(1, mixed.getCount());
    Assert.assertTrue("Incorrect Charset: " + e.getCharset(), text.getContentType().startsWith("text/plain; charset=" + e.getCharset()));
    Assert.assertEquals(specialTextBody, MimeUtility.decodeText(MailTestUtil.getStringContent(text)));
    EmailMessage convertedMessage = MessageConverter.convert(mess);
    Assert.assertEquals(convertedMessage.getSubject(), subject);
}
Also used : MailMessageImpl(com.outjected.email.impl.MailMessageImpl) BodyPart(javax.mail.BodyPart) EmailMessage(com.outjected.email.api.EmailMessage) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) SessionConfig(com.outjected.email.api.SessionConfig) Test(org.junit.Test)

Aggregations

MailMessageImpl (com.outjected.email.impl.MailMessageImpl)34 Test (org.junit.Test)34 Wiser (org.subethamail.wiser.Wiser)21 SessionConfig (com.outjected.email.api.SessionConfig)20 EmailMessage (com.outjected.email.api.EmailMessage)17 MimeMessage (javax.mail.internet.MimeMessage)17 BodyPart (javax.mail.BodyPart)15 MimeMultipart (javax.mail.internet.MimeMultipart)15 MailMessage (com.outjected.email.api.MailMessage)13 URLAttachment (com.outjected.email.impl.attachments.URLAttachment)8 FreeMarkerTemplate (com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate)6 VelocityTemplate (com.outjected.email.impl.templating.velocity.VelocityTemplate)6 SMTPAuthenticator (com.outjected.email.util.SMTPAuthenticator)2 EasyAuthenticationHandlerFactory (org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory)2 EmailContact (com.outjected.email.api.EmailContact)1 BasicEmailContact (com.outjected.email.impl.BasicEmailContact)1 SimpleMailConfig (com.outjected.email.impl.SimpleMailConfig)1 ArrayList (java.util.ArrayList)1