use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.
the class InternetAddressTest method invalidReplyToSimpleAddresses.
@Test(expected = InvalidAddressException.class)
public void invalidReplyToSimpleAddresses() {
MailMessage m = new MailMessageImpl(TestMailConfigs.standardConfig());
m.replyTo("woo foo @bar.com");
}
use of com.outjected.email.impl.MailMessageImpl 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.MailMessageImpl in project simple-email by codylerum.
the class MailMessageTest method testTextMailMessage.
@Test
public void testTextMailMessage() throws MessagingException, IOException {
SessionConfig mailConfig = TestMailConfigs.standardConfig();
String subject = "Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
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(MailTestUtil.getAddressHeader(toName, toAddress)).subject(subject).bodyText(textBody).importance(MessagePriority.HIGH).messageId(messageId).envelopeFrom(ENVELOPE_FROM_ADDRESS).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);
}
use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.
the class MailMessageTest method testTextMailMessageUsingDefaultSession.
@Test
public void testTextMailMessageUsingDefaultSession() throws MessagingException, IOException {
SessionConfig mailConfig = TestMailConfigs.standardConfig();
Person person = new Person(toName, toAddress);
String subject = "Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
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);
}
use of com.outjected.email.impl.MailMessageImpl in project simple-email by codylerum.
the class MailMessageTest method testTextMailMessageInvalidAddress.
@Test(expected = InvalidAddressException.class)
public void testTextMailMessageInvalidAddress() throws SendFailedException {
SessionConfig mailConfig = TestMailConfigs.standardConfig();
String subject = "Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
String messageId = "1234@seam.test.com";
// Port is one off so this should fail
Wiser wiser = new Wiser(mailConfig.getServerPort() + 1);
wiser.setHostname(mailConfig.getServerHost());
try {
wiser.start();
new MailMessageImpl(mailConfig).from("seam seamerson@test.com").replyTo(replyToAddress).to(toAddress, toName).subject(subject).bodyText(textBody).importance(MessagePriority.HIGH).messageId(messageId).send();
} finally {
stop(wiser);
}
}
Aggregations