use of com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate in project simple-email by codylerum.
the class FreeMarkerMailMessageTest method testFreeMarkerTextMailMessage.
@Test
public void testFreeMarkerTextMailMessage() throws MessagingException, IOException {
SessionConfig mailConfig = TestMailConfigs.standardConfig();
EmailMessage e;
String uuid = java.util.UUID.randomUUID().toString();
String subjectTemplate = "Text Message from ${version} Mail - " + uuid;
Person person = new Person(toName, toAddress);
String version = "Seam 3";
String subject = "Text Message from " + version + " Mail - " + uuid;
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(Resources.asCharSource(Resources.getResource("template.text.freemarker"), Charsets.UTF_8).read())).put("person", person).put("version", version).importance(MessagePriority.HIGH).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"));
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(expectedTextBody(person.getName(), version), MailTestUtil.getStringContent(text));
EmailMessage convertedMessage = MessageConverter.convert(mess);
Assert.assertEquals(convertedMessage.getSubject(), subject);
}
Aggregations