Search in sources :

Example 21 with Wiser

use of org.subethamail.wiser.Wiser in project simple-email by codylerum.

the class FreeMarkerMailMessageTest method testTextMailMessageSpecialCharacters.

@Test
public void testTextMailMessageSpecialCharacters() throws MessagingException, IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    EmailMessage e;
    String uuid = java.util.UUID.randomUUID().toString();
    String subjectTemplate = "Special Char ü from ${version} Mail - " + uuid;
    String version = "Seam 3";
    String subject = "Special Char ü from " + version + " Mail - " + uuid;
    String specialTextBody = "This is a Text Body with a special character - ü - ${version}";
    String mergedSpecialTextBody = "This is a Text Body with a special character - ü - " + version;
    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(new FreeMarkerTemplate(subjectTemplate)).bodyText(new FreeMarkerTemplate(specialTextBody)).importance(MessagePriority.HIGH).messageId(messageId).put("version", version).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(mergedSpecialTextBody, 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) FreeMarkerTemplate(com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate) Test(org.junit.Test)

Example 22 with Wiser

use of org.subethamail.wiser.Wiser in project simple-email by codylerum.

the class FreeMarkerMailMessageTest method testFreeMarkerHTMLMailMessage.

@Test
public void testFreeMarkerHTMLMailMessage() throws MessagingException, IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    String subject = "HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
    Person person = new Person(toName, toAddress);
    String version = "Seam 3";
    EmailMessage emailMessage;
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.setHostname(mailConfig.getServerHost());
    try {
        wiser.start();
        emailMessage = new MailMessageImpl(mailConfig).from(MailTestUtil.getAddressHeader(fromName, fromAddress)).replyTo(MailTestUtil.getAddressHeader(replyToName, replyToAddress)).to(person).subject(subject).bodyHtml(new FreeMarkerTemplate(Resources.asCharSource(Resources.getResource("template.html.freemarker"), Charsets.UTF_8).read())).put("person", person).put("version", version).importance(MessagePriority.HIGH).addAttachment(new URLAttachment("http://design.jboss.org/seam/logo/final/seam_mail_85px.png", "seamLogo.png", ContentDisposition.INLINE)).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(replyToName, 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"));
    MimeMultipart mixed = (MimeMultipart) mess.getContent();
    MimeMultipart related = (MimeMultipart) mixed.getBodyPart(0).getContent();
    BodyPart html = related.getBodyPart(0);
    BodyPart attachment1 = related.getBodyPart(1);
    Assert.assertTrue(mixed.getContentType().startsWith("multipart/mixed"));
    Assert.assertEquals(1, mixed.getCount());
    Assert.assertTrue(related.getContentType().startsWith("multipart/related"));
    Assert.assertEquals(2, related.getCount());
    Assert.assertTrue(html.getContentType().startsWith("text/html"));
    Assert.assertEquals(expectedHtmlBody(emailMessage, person.getName(), person.getEmail(), version), MailTestUtil.getStringContent(html));
    Assert.assertTrue(attachment1.getContentType().startsWith("image/png;"));
    Assert.assertEquals("seamLogo.png", attachment1.getFileName());
    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) URLAttachment(com.outjected.email.impl.attachments.URLAttachment) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) SessionConfig(com.outjected.email.api.SessionConfig) FreeMarkerTemplate(com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate) Test(org.junit.Test)

Example 23 with Wiser

use of org.subethamail.wiser.Wiser in project simple-email by codylerum.

the class FreeMarkerMailMessageTest method testFreeMarkerTextMailMessageSendFailed.

@Test(expected = SendFailedException.class)
public void testFreeMarkerTextMailMessageSendFailed() throws IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    String uuid = java.util.UUID.randomUUID().toString();
    String subject = "Text Message from $version Mail - " + uuid;
    Person person = new Person(toName, toAddress);
    String version = "Seam 3";
    // Port is two off so this should fail
    Wiser wiser = new Wiser(mailConfig.getServerPort() + 2);
    wiser.setHostname(mailConfig.getServerHost());
    try {
        wiser.start();
        person.setName(toName);
        person.setEmail(toAddress);
        new MailMessageImpl(mailConfig).from(fromAddress).replyTo(replyToAddress).to(toAddress).subject(new FreeMarkerTemplate(subject)).bodyText(new FreeMarkerTemplate(Resources.asCharSource(Resources.getResource("template.text.freemarker"), Charsets.UTF_8).read())).put("person", person).put("version", version).importance(MessagePriority.HIGH).send();
    } finally {
        stop(wiser);
    }
}
Also used : MailMessageImpl(com.outjected.email.impl.MailMessageImpl) Wiser(org.subethamail.wiser.Wiser) SessionConfig(com.outjected.email.api.SessionConfig) FreeMarkerTemplate(com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate) Test(org.junit.Test)

Example 24 with Wiser

use of org.subethamail.wiser.Wiser in project simple-email by codylerum.

the class FreeMarkerMailMessageTest method testSMTPSessionAuthentication.

@Test
public void testSMTPSessionAuthentication() throws MessagingException, IOException {
    SimpleMailConfig mailConfig = TestMailConfigs.gmailConfig();
    String subject = "HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
    Person person = new Person(toName, toAddress);
    mailConfig.setServerHost("localHost");
    mailConfig.setServerPort(8978);
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.getServer().setAuthenticationHandlerFactory(new EasyAuthenticationHandlerFactory(new SMTPAuthenticator("test", "test12!")));
    try {
        wiser.start();
        new MailMessageImpl(mailConfig).from(fromAddress).to(person.getEmail()).subject(subject).put("person", person).put("version", "Seam 3").bodyHtmlTextAlt(new FreeMarkerTemplate(Resources.asCharSource(Resources.getResource("template.html.freemarker"), Charsets.UTF_8).read()), new FreeMarkerTemplate(Resources.asCharSource(Resources.getResource("template.text.freemarker"), Charsets.UTF_8).read())).importance(MessagePriority.LOW).deliveryReceipt(fromAddress).readReceipt(fromAddress).addAttachment("template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT, Resources.asByteSource(Resources.getResource("template.html.freemarker")).read()).addAttachment(new URLAttachment("http://design.jboss.org/seam/logo/final/seam_mail_85px.png", "seamLogo.png", ContentDisposition.INLINE)).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.unfold(mess.getHeader("Subject", null)));
    EmailMessage convertedMessage = MessageConverter.convert(mess);
    Assert.assertEquals(convertedMessage.getSubject(), subject);
}
Also used : MailMessageImpl(com.outjected.email.impl.MailMessageImpl) EmailMessage(com.outjected.email.api.EmailMessage) SMTPAuthenticator(com.outjected.email.util.SMTPAuthenticator) URLAttachment(com.outjected.email.impl.attachments.URLAttachment) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) SimpleMailConfig(com.outjected.email.impl.SimpleMailConfig) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) FreeMarkerTemplate(com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate) Test(org.junit.Test)

Example 25 with Wiser

use of org.subethamail.wiser.Wiser in project camunda-bpm-platform by camunda.

the class EmailTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    int port = processEngineConfiguration.getMailServerPort();
    boolean serverUpAndRunning = false;
    while (!serverUpAndRunning) {
        wiser = new Wiser();
        wiser.setPort(port);
        try {
            LOG.info("Starting Wiser mail server on port: " + port);
            wiser.start();
            serverUpAndRunning = true;
            LOG.info("Wiser mail server listening on port: " + port);
        } catch (RuntimeException e) {
            // Fix for slow port-closing Jenkins
            if (e.getMessage().toLowerCase().contains("BindException")) {
                Thread.sleep(250L);
            }
        }
    }
}
Also used : Wiser(org.subethamail.wiser.Wiser)

Aggregations

Wiser (org.subethamail.wiser.Wiser)43 MailMessageImpl (com.outjected.email.impl.MailMessageImpl)21 Test (org.junit.Test)21 SessionConfig (com.outjected.email.api.SessionConfig)20 MimeMessage (javax.mail.internet.MimeMessage)18 EmailMessage (com.outjected.email.api.EmailMessage)17 BodyPart (javax.mail.BodyPart)15 MimeMultipart (javax.mail.internet.MimeMultipart)15 Before (org.junit.Before)9 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 BeforeClass (org.junit.BeforeClass)4 ChainedProperties (org.kie.internal.utils.ChainedProperties)4 SMTPAuthenticator (com.outjected.email.util.SMTPAuthenticator)2 File (java.io.File)2 EasyAuthenticationHandlerFactory (org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory)2 SimpleMailConfig (com.outjected.email.impl.SimpleMailConfig)1 PortalContainer (org.exoplatform.container.PortalContainer)1 DefaultUserInfo (org.jbpm.services.task.identity.DefaultUserInfo)1