diff --git a/modules/core-module/src/main/java/org/simplejavamail/api/email/EmailPopulatingBuilder.java b/modules/core-module/src/main/java/org/simplejavamail/api/email/EmailPopulatingBuilder.java index 48291686..42720c21 100644 --- a/modules/core-module/src/main/java/org/simplejavamail/api/email/EmailPopulatingBuilder.java +++ b/modules/core-module/src/main/java/org/simplejavamail/api/email/EmailPopulatingBuilder.java @@ -1532,6 +1532,13 @@ public interface EmailPopulatingBuilder { @SuppressWarnings("unused") EmailPopulatingBuilder clearRecipients(); + /** + * Resets overrideReceivers to empty. + * + * @see #withOverrideReceivers(List) + */ + EmailPopulatingBuilder clearOverrideReceivers(); + /** * Resets base dir for embedded images to {@code null}. */ diff --git a/modules/core-module/src/main/java/org/simplejavamail/api/email/EqualsHelper.java b/modules/core-module/src/main/java/org/simplejavamail/api/email/EqualsHelper.java index 84bb280d..64f9a896 100644 --- a/modules/core-module/src/main/java/org/simplejavamail/api/email/EqualsHelper.java +++ b/modules/core-module/src/main/java/org/simplejavamail/api/email/EqualsHelper.java @@ -55,10 +55,12 @@ public static boolean equalsEmail(final Email email1, final Email email2) { if (!fieldIsEqual(email1.getSubject(), email2.getSubject(), "subject")) { return false; } - if (!isEqualRecipientList(email1.getRecipients(), email2.getRecipients())) { return false; } + if (!isEqualRecipientList(email1.getOverrideReceivers(), email2.getOverrideReceivers())) { + return false; + } if (!email1.getEmbeddedImages().containsAll(email2.getEmbeddedImages()) || !email2.getEmbeddedImages().containsAll(email1.getEmbeddedImages())) { return false; } diff --git a/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java b/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java index 0cd52b38..8f03dda8 100644 --- a/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java +++ b/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java @@ -2232,6 +2232,15 @@ public EmailPopulatingBuilder clearRecipients() { return this; } + /** + * @see EmailPopulatingBuilder#clearOverrideReceivers() + */ + @Override + public EmailPopulatingBuilder clearOverrideReceivers() { + this.overrideReceivers.clear(); + return this; + } + /** * @see EmailPopulatingBuilder#clearEmbeddedImageBaseDir() */ diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java index f7b0bbd1..1d5b0602 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java @@ -467,6 +467,9 @@ private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopul .withHeader("governanceOverrideTest1", "overridden", true) .withHeader("governanceOverrideTest2", "also overridden", true); + // envelope-level receivers would have been lost in the received Message, so we need to compensate for that + originalEmailPopulatingBuilder.clearOverrideReceivers(); + if (!skipChecksDueToSmime) { // reading a signed mail is different from building a new one assertThat(receivedEmail).isEqualTo(originalEmailPopulatingBuilder.buildEmail()); } else {