我正在尝试使用 Greenmail 为 Spring Email 编写测试代码。这与 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;
}