use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class EmailConverter method outlookMsgToEmailBuilder.
/**
* @param msgInputStream The content of an Outlook (.msg) message from which to create the {@link Email}.
*/
public static EmailPopulatingBuilder outlookMsgToEmailBuilder(@Nonnull final InputStream msgInputStream) {
final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
final OutlookMessage outlookMessage = OutlookMessageParser.parseOutlookMsg(checkNonEmptyArgument(msgInputStream, "msgInputStream"));
buildEmailFromOutlookMessage(emailPopulatingBuilder, outlookMessage);
return emailPopulatingBuilder;
}
use of org.simplejavamail.email.EmailPopulatingBuilder 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()));
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_ReplyToMessage_NotAll_AndCustomReferences.
@Test
public void createMailSession_ReplyToMessage_NotAll_AndCustomReferences() 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.replyingTo(assertSendingEmail(receivedEmailPopulatingBuilder)).withHeader("References", "dummy-references").from("dummy@domain.com").withPlainText("This is the reply").buildEmail();
// test received reply to initial mail
mailer.sendMail(reply);
MimeMessage receivedMimeMessageReply1 = smtpServerRule.getOnlyMessage("lo.pop.replyto@somemail.com");
Email receivedReply = mimeMessageToEmail(receivedMimeMessageReply1);
EmailAssert.assertThat(receivedReply).hasSubject("Re: hey");
EmailAssert.assertThat(receivedReply).hasOnlyRecipients(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", TO));
assertThat(receivedReply.getHeaders()).contains(entry("In-Reply-To", receivedEmailPopulatingBuilder.getId()));
assertThat(receivedReply.getHeaders()).contains(entry("References", "dummy-references"));
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class EmailConverter method outlookMsgToEmail.
/**
* @param msgfile The content of an Outlook (.msg) message from which to create the {@link Email}.
*/
public static Email outlookMsgToEmail(@Nonnull final File msgfile) {
final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
final OutlookMessage outlookMessage = OutlookMessageParser.parseOutlookMsg(checkNonEmptyArgument(msgfile, "msgfile"));
buildEmailFromOutlookMessage(emailPopulatingBuilder, outlookMessage);
return emailPopulatingBuilder.buildEmail();
}
use of org.simplejavamail.email.EmailPopulatingBuilder in project simple-java-mail by bbottema.
the class EmailHelper method createDummyEmailBuilder.
public static EmailPopulatingBuilder createDummyEmailBuilder(@Nullable String id, boolean includeSubjectAndBody, boolean basicFields, boolean includeCustomHeaders) throws IOException {
EmailPopulatingBuilder builder = EmailBuilder.startingBlank().fixingMessageId(id).from("lollypop", "lol.pop@somemail.com").to("C.Cane", "candycane@candyshop.org");
if (!basicFields) {
// normally not needed, but for the test it is because the MimeMessage will
// have it added automatically as well, so the parsed Email will also have it then
builder = builder.withReplyTo("lollypop-reply", "lol.pop.reply@somemail.com").withBounceTo("lollypop-bounce", "lol.pop.bounce@somemail.com");
}
if (includeSubjectAndBody) {
builder = builder.withSubject("hey").withPlainText("We should meet up!").withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>");
}
if (includeCustomHeaders) {
builder = builder.withHeader("dummyHeader", "dummyHeaderValue").withDispositionNotificationTo("simple@address.com").withReturnReceiptTo("Complex Email", "simple@address.com");
}
// add two text files in different ways and a black thumbs up embedded image ->
ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
// normally not needed, but otherwise the equals will fail
namedAttachment.setName("dresscode.txt");
String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
return builder.withAttachment("dresscode.txt", namedAttachment).withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain").withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png");
}
Aggregations