带有Greenmail的Spring电子邮件:身份验证凭据无效

问题描述 投票:1回答:1

我正在尝试使用Greenmail为Spring Email编写测试代码。这与Greenmail的1.5.5版本完全兼容,但是当我尝试更新Greenmail的版本(从1.5.6到1.5.11)时,它会不断给我一个错误535 5.7.8身份验证凭据无效。

应用程序属性

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

这是我的代码

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;
}
java spring junit javamail greenmail
1个回答
0
投票

我在1.5.13中遇到了同样的问题,如果您从配置/代码中删除凭据,它将起作用。

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

并且来自beforeClass()方法:

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

[Greenmail不需要身份验证就可以接受所有入站连接,但是尚不清楚为什么1.5.5可以这样工作,以及为什么它不能用于较新的版本。

© www.soinside.com 2019 - 2024. All rights reserved.