'Spring Email with Greenmail: Authentication Credentials Invalid

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;
}


Solution 1:[1]

I had the same problem with 1.5.13, it will work if you remove the credentials from the config/code.

# spring.mail.username=username     
# spring.mail.password=secret

and from the beforeClass() method:

// smtpServer.setUser("username", "secret");

Greenmail accepts all inbound connections without the need for authentication, but it's unclear why 1.5.5 worked like this and why it doesn't with the newer versions.

Solution 2:[2]

I had the same problem with greenmail-1.6.8.

According to this, I have created the GreenMail object as follows

GreenMail greenMail = new GreenMail(new ServerSetup(3025, null, "smtp")).withConfiguration(GreenMailConfiguration.aConfig().withDisabledAuthentication());
greenMail.start();

And all tests passed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 antonyh
Solution 2 GeorgePap