I am trying to write test code for Spring Email using Greenmail. This works perfectly with 1.5.5 version of Greenmail, however when I try to update the version of Greenmail (1.5.6 to 1.5.11) it keeps giving me an error 535 5.7.8 Authentication credentials invalid.
Application Properties
spring.mail.default-encoding=UTF-8
spring.mail.host=localhost
spring.mail.port=3025
spring.mail.jndi-name=
spring.mail.test-connection=false
spring.mail.username=username
spring.mail.password=secret
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls=true
spring.mail.properties.mail.smtp.debug=false
Here are my code
protected static GreenMail smtpServer;
@Autowired
protected EmailRepository emailRepository;
@BeforeClass
public static void beforeClass() {
smtpServer = new GreenMail(new ServerSetup(3025, null, ServerSetup.PROTOCOL_SMTP ));
smtpServer.setUser("username", "secret");
smtpServer.start();
}
@Before
public void before() {
emailRepository.deleteAll();
smtpServer.reset();
}
@After
public void after() {
emailRepository.deleteAll();
}
@AfterClass
public static void afterClass() {
smtpServer.stop();
}
protected List<Email> createEmailRequests(int size, EmailStatus status) {
int counter = 0;
List<Email> emails = new ArrayList<>();
do {
MetaInfo metaInfo = new MetaInfo();
//metainfo details
Email email = new Email();
//email details
emails.add(email);
counter++;
} while (counter < size);
emailRepository.saveAll(emails);
return emails;
}
code with Greenmail 1.5.5 (that gives: jakarta.mail.AuthenticationFailedException: 535 5.7.8 Authentication credentials invalid with 2.0.0)
code with Greenmail 2.0.0
this made it work for me