use of org.simplejavamail.email.Email in project simple-java-mail by bbottema.
the class MimeMessageHelperTest method testSignMessageWithDKIM_ShouldFailSpecificallyBecauseItWillTryToSign.
@Test
public void testSignMessageWithDKIM_ShouldFailSpecificallyBecauseItWillTryToSign() throws IOException {
final Email email = EmailHelper.createDummyEmailBuilder(true, false, false).signWithDomainKey("dummykey", "moo.com", "selector").buildEmail();
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
EmailConverter.emailToMimeMessage(email);
}
}).hasMessage(MimeMessageParseException.ERROR_SIGNING_DKIM_INVALID_DOMAINKEY);
}
use of org.simplejavamail.email.Email 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.Email 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.Email in project simple-java-mail by bbottema.
the class MailerLiveTest method assertSendingEmail.
private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopulatingBuilder) throws MessagingException {
Email originalEmail = originalEmailPopulatingBuilder.buildEmail();
mailer.sendMail(originalEmail);
MimeMessage receivedMimeMessage = smtpServerRule.getOnlyMessage();
assertThat(receivedMimeMessage.getMessageID()).isEqualTo(originalEmail.getId());
Email receivedEmail = mimeMessageToEmail(receivedMimeMessage);
// hack: it seems Wiser automatically defaults replyTo address to the From address if left empty
if (originalEmailPopulatingBuilder.getReplyToRecipient() == null) {
originalEmailPopulatingBuilder.withReplyTo(originalEmailPopulatingBuilder.getFromRecipient());
}
// received email will always have an id, so let's make sure we're able to compare to the original email object
if (originalEmailPopulatingBuilder.getHeaders().get("Message-ID") == null) {
originalEmailPopulatingBuilder.withHeader("Message-ID", originalEmail.getId());
}
// bounce recipient is not part of the Mimemessage, but the Envelope and is configured on the Session, so just ignore this
if (originalEmailPopulatingBuilder.getBounceToRecipient() != null) {
originalEmailPopulatingBuilder.clearBounceTo();
}
assertThat(receivedEmail).isEqualTo(originalEmailPopulatingBuilder.buildEmail());
return receivedEmail;
}
Aggregations