0

I am implementing tests for a service which sends a lot of emails. As a testing tool I selected GreenMail.

I'm doing like

@Rule
public GreenMailRule mail = new GreenMailRule(ServerSetupTest.SMTP);

@Autowired
MailService mailService;

@Before
public void setUp() {
    mail.setUser("recipient1@email.com", "recipient1@email.com", "password");
    mail.setUser("recipient2@email.com", "recipient2@email.com", "password").create();
    mail.setUser("sender@email.com", "sender@email.com", "p").create();
    mail.start();
}

@Test
public void test() {
  // sends mail from sender@email.com to recipient1 and recipient2 using cc
  mailService.send();
  mail.setUser("recipient1@email.com", "password");
  assertEquals(1, mail.getReceivedMessages().length);
}

However, I got 2 messages - for both recipients. I think that the reason is smtp based for posting not reading. However if use POP3, I receive no messages at all.

So how can I get messages for specific user?

Rahul
  • 1,727
  • 3
  • 18
  • 33
  • AFAIK you cannot. It is s simple server for testing it doesn't provide mailboxes etc. you can only test if the mail got send not if it got dispatched correctly. – M. Deinum Oct 14 '16 at 13:54
  • 1
    See the [javadoc](http://www.icegreen.com/greenmail/javadocs/com/icegreen/greenmail/util/Retriever.html). You would need a `Retriever` for that. – M. Deinum Oct 14 '16 at 14:06
  • @M.Deinum great thanks! Exactly what I needed – Rahul Oct 14 '16 at 16:22

0 Answers0