我正在尝试使用Greenmail为Spring电子邮件编写测试代码。这在1.5.5版本的Greenmail上工作得很好,但是当我尝试更新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;
}发布于 2020-04-24 22:17:50
我在1.5.13中也遇到了同样的问题,如果您从config/code中删除凭据,它将会正常工作。
# spring.mail.username=username
# spring.mail.password=secret并且来自beforeClass()方法:
// smtpServer.setUser("username", "secret");Greenmail接受所有的入站连接,不需要身份验证,但不清楚为什么1.5.5可以这样工作,为什么它不能与新版本一起工作。
https://stackoverflow.com/questions/60965233
复制相似问题