use of org.simplejavamail.email.Recipient in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageTest.
@Test
public void createMailSession_OutlookMessageTest() throws IOException, MessagingException {
Email email = assertSendingEmail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg"));
// Google SMTP overrode this, Outlook recognized it as: Benny Bottema <b.bottema@gmail.com>; on behalf of; lollypop <b.bottema@projectnibble.org>
EmailAssert.assertThat(email).hasFromRecipient(new Recipient("lollypop", "b.bottema@projectnibble.org", null));
EmailAssert.assertThat(email).hasSubject("hey");
// Outlook overrode this when saving the .email to match the mail account
EmailAssert.assertThat(email).hasRecipients(new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO));
EmailAssert.assertThat(email).hasReplyToRecipient(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", null));
assertThat(normalizeText(email.getPlainText())).isEqualTo("We should meet up!\n");
// Outlook overrode this value too OR converted the original HTML to RTF, from which OutlookMessageParser derived this HTML
assertThat(normalizeText(email.getHTMLText())).contains("<html><body style=\"font-family:'Courier',monospace;font-size:10pt;\"> <br/> <br/> <b> We should meet up! <br/> </b> <br/> <img src=\"cid:thumbsup\"> <br/> ");
// the RTF was probably created by Outlook based on the HTML when the message was saved
assertThat(email.getAttachments()).hasSize(2);
assertThat(email.getEmbeddedImages()).hasSize(1);
AttachmentResource attachment1 = email.getAttachments().get(0);
AttachmentResource attachment2 = email.getAttachments().get(1);
AttachmentResource embeddedImg = email.getEmbeddedImages().get(0);
// Outlook overrode dresscode.txt, presumably because it was more than 8 character long??
assertAttachmentMetadata(attachment1, "text/plain", "dresscode.txt");
assertAttachmentMetadata(attachment2, "text/plain", "location.txt");
assertAttachmentMetadata(embeddedImg, "image/png", "thumbsup");
assertThat(normalizeText(attachment1.readAllData())).isEqualTo("Black Tie Optional");
assertThat(normalizeText(attachment2.readAllData())).isEqualTo("On the moon!");
}
use of org.simplejavamail.email.Recipient in project simple-java-mail by bbottema.
the class MimeMessageHelper method setRecipients.
/**
* Fills the {@link Message} instance with recipients from the {@link Email}.
*
* @param email The message in which the recipients are defined.
* @param message The javax message that needs to be filled with recipients.
* @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
* @throws MessagingException See {@link Message#addRecipient(Message.RecipientType, Address)}
*/
private static void setRecipients(final Email email, final Message message) throws UnsupportedEncodingException, MessagingException {
for (final Recipient recipient : email.getRecipients()) {
final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
message.addRecipient(recipient.getType(), address);
}
}
use of org.simplejavamail.email.Recipient in project simple-java-mail by bbottema.
the class MimeMessageHelper method setReplyTo.
/**
* Fills the {@link Message} instance with reply-to address.
*
* @param email The message in which the recipients are defined.
* @param message The javax message that needs to be filled with reply-to address.
* @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
* @throws MessagingException See {@link Message#setReplyTo(Address[])}
*/
private static void setReplyTo(final Email email, final Message message) throws UnsupportedEncodingException, MessagingException {
final Recipient replyToRecipient = email.getReplyToRecipient();
if (replyToRecipient != null) {
final InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(), CHARACTER_ENCODING);
message.setReplyTo(new Address[] { replyToAddress });
}
}
use of org.simplejavamail.email.Recipient in project simple-java-mail by bbottema.
the class MiscUtilTest method testAddRecipientByInternetAddress.
@Test
public void testAddRecipientByInternetAddress() {
assertThat(MiscUtil.interpretRecipient(null, false, "a@b.com", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " a@b.com ", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " <a@b.com> ", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " < a@b.com > ", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "moo <a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "moo<a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " moo< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\" <a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\"<a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " \"moo\"< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \"< a@b.com > ", null)).isEqualTo(new Recipient(" m oo ", "a@b.com", null));
// next one is unparsable by InternetAddress#parse(), so it should be taken as is
assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \" a@b.com ", null)).isEqualTo(new Recipient(null, " \" m oo \" a@b.com ", null));
}
use of org.simplejavamail.email.Recipient in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_ReplyToMessage.
@Test
public void createMailSession_ReplyToMessage() throws IOException, MessagingException {
// send initial mail
mailer.sendMail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg").buildEmail());
MimeMessage receivedMimeMessage = smtpServerRule.getOnlyMessage();
EmailPopulatingBuilder receivedEmailPopulatingBuilder = mimeMessageToEmailBuilder(receivedMimeMessage);
// send reply to initial mail
Email reply = EmailBuilder.replyingToAll(assertSendingEmail(receivedEmailPopulatingBuilder)).from("dummy@domain.com").withPlainText("This is the reply").buildEmail();
// test received reply to initial mail
mailer.sendMail(reply);
MimeMessage receivedMimeMessageReply1 = smtpServerRule.getMessage("lo.pop.replyto@somemail.com");
MimeMessage receivedMimeMessageReply2 = smtpServerRule.getMessage("benny.bottema@aegon.nl");
Email receivedReply1 = mimeMessageToEmail(receivedMimeMessageReply1);
Email receivedReply2 = mimeMessageToEmail(receivedMimeMessageReply2);
assertThat(receivedReply1).isEqualTo(receivedReply2);
EmailAssert.assertThat(receivedReply1).hasSubject("Re: hey");
EmailAssert.assertThat(receivedReply1).hasOnlyRecipients(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", TO), new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO));
assertThat(receivedReply1.getHeaders()).contains(entry("In-Reply-To", receivedEmailPopulatingBuilder.getId()));
assertThat(receivedReply1.getHeaders()).contains(entry("References", receivedEmailPopulatingBuilder.getId()));
}
Aggregations