1

我使用 Spring Email 编写了一个电子邮件服务,然后使用 Greenmail 测试了电子邮件服务。但是在运行测试用例时,它给出了一个错误 Authentication failed ,如下所示:

javax.mail.AuthenticationFailedException: 535 5.7.0 身份验证凭据在 com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965) 在 com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java) 无效:876)

如果不在代码中提供我的用户名/密码,如何解决此错误。请注意,我也尝试过提供用户名/密码,但由于同样的异常而失败。谢谢你的帮助。

4

3 回答 3

3
greenMail = new GreenMail(new ServerSetup(2525, "127.0.0.1", "smtp"));
greenMail.setUser("username", "secret");

在设置您的 greenmail 实例进行测试时,您需要使用 setUser 并在上面输入用户名和密码,然后添加上面@One Guy 帖子中指定的属性。在我收到身份验证凭据无效异常后为我工作。

希望这可以帮助任何面临这个问题的人

于 2020-01-23T12:09:52.017 回答
0

请参阅AuthenticationDisabledTest.java如何使用禁用身份验证配置 GreenMail junit 测试。

于 2019-12-26T22:24:48.687 回答
0

看起来您没有添加模拟凭据,即application-test.yml位于src/test/resources文件夹中的名为 file 的资源文件。

应用程序.yml

spring:
  mail:
    default-encoding: UTF-8
    host: localhost
    jndi-name:
    username: username
    password: secret
    port: 2525
    properties:
      mail:
        debug: false
        smtp:
          debug: false
          auth: true
          starttls: true
    protocol: smtp
    test-connection: false

您可以通过以下链接查看示例:

https://memorynotfound.com/spring-mail-integration-testing-junit-greenmail-example/

于 2019-06-24T00:23:04.117 回答