Search in sources :

Example 6 with VelocityTemplate

use of com.outjected.email.impl.templating.velocity.VelocityTemplate in project simple-email by codylerum.

the class VelocityMailMessageTest method testSMTPSessionAuthentication.

@Test
public void testSMTPSessionAuthentication() throws MessagingException, IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    Person person = new Person(toName, toAddress);
    String subject = "HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.setHostname(mailConfig.getServerHost());
    wiser.getServer().setAuthenticationHandlerFactory(new EasyAuthenticationHandlerFactory(new SMTPAuthenticator("test", "test12!")));
    try {
        wiser.start();
        new MailMessageImpl(mailConfig).from(fromAddress).to(person.getEmail()).subject(subject).put("version", "Seam 3").bodyHtmlTextAlt(new VelocityTemplate(Resources.asCharSource(Resources.getResource("template.html.velocity"), Charsets.UTF_8).read()), new VelocityTemplate(Resources.asCharSource(Resources.getResource("template.text.velocity"), Charsets.UTF_8).read())).importance(MessagePriority.LOW).deliveryReceipt(fromAddress).readReceipt(fromAddress).addAttachment("template.html.velocity", "text/html", ContentDisposition.ATTACHMENT, Resources.asByteSource(Resources.getResource("template.html.velocity")).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 : VelocityTemplate(com.outjected.email.impl.templating.velocity.VelocityTemplate) 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) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) SessionConfig(com.outjected.email.api.SessionConfig) Test(org.junit.Test)

Aggregations

SessionConfig (com.outjected.email.api.SessionConfig)6 MailMessageImpl (com.outjected.email.impl.MailMessageImpl)6 VelocityTemplate (com.outjected.email.impl.templating.velocity.VelocityTemplate)6 Test (org.junit.Test)6 Wiser (org.subethamail.wiser.Wiser)6 EmailMessage (com.outjected.email.api.EmailMessage)5 MimeMessage (javax.mail.internet.MimeMessage)5 BodyPart (javax.mail.BodyPart)4 MimeMultipart (javax.mail.internet.MimeMultipart)4 URLAttachment (com.outjected.email.impl.attachments.URLAttachment)3 SMTPAuthenticator (com.outjected.email.util.SMTPAuthenticator)1 EasyAuthenticationHandlerFactory (org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory)1