Open mpschaeuble opened 7 months ago
Thx, @mpschaeuble
You could use IMAP connection to fetch mails for a specific user:
try (final IMAPStore store = greenMail.getImap().createStore()) {
store.connect("first@a.com", "first@a.com"); // Login as first@a.com
Folder inboxFolder = store.getFolder("INBOX");
inboxFolder.open(Folder.READ_ONLY);
final Message[] messages = inboxFolder.getMessages();
assertThat(messages).hasSize(1);
// Unsure: Should mail keep both recipients, or only receiving 'first@a.com'
assertThat(GreenMailUtil.getAddressList(messages[0].getRecipients(Message.RecipientType.TO)))
.isEqualTo("first@a.com, second@b.com");
}
I'll have to check about each delivered mail about keeping both recipients.
I'm currently using Greenmail 2.0.1 in JUnit5 tests and I'm not sure whether it's a bug or this is the expected behaviour: When sending a single mail to two different recipients, e.g. using
GreenMailUtil.sendTextEmailTest("first@a.com,second@b.com", "from@localhost", "subject", "body");
, I observe the following behaviour:greenMail.getReceivedMessages()
-> returns two resultsgetReceivedMessagesForDomain("a.com")
-> returns two resultsgetReceivedMessagesForDomain("b.com")
-> returns two resultsI would either expect getReceivedMessages() to return a single result (because it's one mail) or both getReceivedMessagesForDomain(...) to return a single result in this case. Is my expectation wrong? How can I verify a single mail is sent by my application under test to two different recipients?