use of com.outjected.email.impl.attachments.URLAttachment in project simple-email by codylerum.
the class MailMessageTest method testHTMLTextAltMailMessage.
@Test
public void testHTMLTextAltMailMessage() throws MessagingException, IOException {
SessionConfig mailConfig = TestMailConfigs.standardConfig();
String subject = "HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
Person person = new Person(toName, toAddress);
Wiser wiser = new Wiser(mailConfig.getServerPort());
wiser.setHostname(mailConfig.getServerHost());
try {
wiser.start();
new MailMessageImpl(mailConfig).from(MailTestUtil.getAddressHeader(fromName, fromAddress)).to(person).subject(subject).bodyHtmlTextAlt(htmlBody, textBody).importance(MessagePriority.LOW).deliveryReceipt(fromAddress).readReceipt(fromAddress).addAttachment("template.text.velocity", "text/plain", ContentDisposition.ATTACHMENT, Resources.asByteSource(Resources.getResource("template.text.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(MailTestUtil.getAddressHeader(fromName, fromAddress), mess.getHeader("From", 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.LOW.getPriority(), mess.getHeader("Priority", null));
Assert.assertEquals(MessagePriority.LOW.getX_priority(), mess.getHeader("X-Priority", null));
Assert.assertEquals(MessagePriority.LOW.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();
MimeMultipart alternative = (MimeMultipart) related.getBodyPart(0).getContent();
BodyPart attachment = mixed.getBodyPart(1);
BodyPart inlineAttachment = related.getBodyPart(1);
BodyPart textAlt = alternative.getBodyPart(0);
BodyPart html = alternative.getBodyPart(1);
Assert.assertTrue(mixed.getContentType().startsWith("multipart/mixed"));
Assert.assertEquals(2, mixed.getCount());
Assert.assertTrue(related.getContentType().startsWith("multipart/related"));
Assert.assertEquals(2, related.getCount());
Assert.assertTrue(html.getContentType().startsWith("text/html"));
Assert.assertEquals(htmlBody, MailTestUtil.getStringContent(html));
Assert.assertTrue(textAlt.getContentType().startsWith("text/plain"));
Assert.assertEquals(textBody, MailTestUtil.getStringContent(textAlt));
Assert.assertTrue(attachment.getContentType().startsWith("text/plain"));
Assert.assertEquals("template.text.velocity", attachment.getFileName());
Assert.assertTrue(inlineAttachment.getContentType().startsWith("image/png;"));
Assert.assertEquals("seamLogo.png", inlineAttachment.getFileName());
EmailMessage convertedMessage = MessageConverter.convert(mess);
Assert.assertEquals(convertedMessage.getSubject(), subject);
}
use of com.outjected.email.impl.attachments.URLAttachment in project simple-email by codylerum.
the class VelocityMailMessageTest method testVelocityHTMLTextAltMailMessage.
@Test
public void testVelocityHTMLTextAltMailMessage() 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();
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)).to(MailTestUtil.getAddressHeader(person.getName(), person.getEmail())).subject(subject).put("version", version).put("person", person).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(MailTestUtil.getAddressHeader(fromName, fromAddress), mess.getHeader("From", 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.LOW.getPriority(), mess.getHeader("Priority", null));
Assert.assertEquals(MessagePriority.LOW.getX_priority(), mess.getHeader("X-Priority", null));
Assert.assertEquals(MessagePriority.LOW.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();
MimeMultipart alternative = (MimeMultipart) related.getBodyPart(0).getContent();
BodyPart attachment = mixed.getBodyPart(1);
BodyPart inlineAttachment = related.getBodyPart(1);
BodyPart textAlt = alternative.getBodyPart(0);
BodyPart html = alternative.getBodyPart(1);
Assert.assertTrue(mixed.getContentType().startsWith("multipart/mixed"));
Assert.assertEquals(2, 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(textAlt.getContentType().startsWith("text/plain"));
Assert.assertEquals(expectedTextBody(person.getName(), version), MailTestUtil.getStringContent(textAlt));
Assert.assertTrue(attachment.getContentType().startsWith("text/html"));
Assert.assertEquals("template.html.velocity", attachment.getFileName());
Assert.assertTrue(inlineAttachment.getContentType().startsWith("image/png;"));
Assert.assertEquals("seamLogo.png", inlineAttachment.getFileName());
EmailMessage convertedMessage = MessageConverter.convert(mess);
Assert.assertEquals(convertedMessage.getSubject(), subject);
}
use of com.outjected.email.impl.attachments.URLAttachment in project simple-email by codylerum.
the class VelocityMailMessageTest method testVelocityHTMLMailMessage.
@Test
public void testVelocityHTMLMailMessage() throws MessagingException, IOException {
SessionConfig mailConfig = TestMailConfigs.standardConfig();
Person person = new Person(toName, toAddress);
String subject = "HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
String version = "Seam 3";
EmailMessage emailMessage;
Wiser wiser = new Wiser(mailConfig.getServerPort());
wiser.setHostname(mailConfig.getServerHost());
try {
wiser.start();
person.setName(toName);
person.setEmail(toAddress);
emailMessage = new MailMessageImpl(mailConfig).from(MailTestUtil.getAddressHeader(fromName, fromAddress)).replyTo(MailTestUtil.getAddressHeader(replyToName, replyToAddress)).to(person).subject(subject).bodyHtml(new VelocityTemplate(Resources.asCharSource(Resources.getResource("template.html.velocity"), Charsets.UTF_8).read())).put("version", version).put("person", person).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);
}
use of com.outjected.email.impl.attachments.URLAttachment 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);
}
use of com.outjected.email.impl.attachments.URLAttachment 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);
}
Aggregations