【问题标题】:Found javax.mail.AuthenticationFailedException: failed to connect, no password specified? while listenning new mails where the password is correct发现 javax.mail.AuthenticationFailedException:连接失败,没有指定密码?在收听密码正确的新邮件时
【发布时间】:2020-04-25 17:02:21
【问题描述】:

我在使用 spring 集成连接 imap gmail 商店时遇到了这个异常。请看一下代码 {@自动连线 私有IntegrationFlowContext flowContext;

    public void startMail(String user, String pw) {
        IntegrationFlow flow = IntegrationFlows
                .from(Mail.imapIdleAdapter(imapUrl(user, pw))
                        .javaMailProperties(p -> p.put("mail.debug", "true"))
                        //.userFlag("testSIUserFlag") // needed by the SI test server - not needed if server supports /SEEN
                        .headerMapper(new DefaultMailHeaderMapper()))
                .handle(System.out::println)
                .get();
        this.flowContext.registration(flow).register();
    }}

其中 imapUrl(user, pw) 返回网址为 imap://xyz.abc@gmail.com:xxxxx@imap.gmail.com:993/INBOX

请帮我摆脱这个异常。

注意:我读过一篇帖子 here 说需要在凭据中转义“@”。作为java spring boot的新手,请告诉我如何逃避'@'

【问题讨论】:

    标签: java spring-integration dsl


    【解决方案1】:

    GMail 默认不支持 JavaMail 客户端;您必须启用“不太安全的客户端”(或类似的东西)。

    使用%40 替换@。

    https://www.werockyourweb.com/url-escape-characters/

    【讨论】:

    • 你应该只替换第一个。
    • 是的...“不太安全”对我不起作用,但我已经通过support.google.com/accounts/answer/185833 解决了这个问题。所以,两个工厂和应用程序密码。有关 GMail 专用的 java 邮件属性,另请参见此处:github.com/spring-projects/spring-integration/issues/…
    • Gary,我们应该只替换用户 ID 或密码中的 @。所以我做到了,仍然没有运气
    • Artem,添加所有相关属性后...仍然面临同样的问题
    • 其实是@gmail.com的时候。 IMAP URL 中不需要此后缀 - 只需您的帐户即可。例如,当我连接时,我的一个是这样的:imaps://clericsmail:[APP_PASSWORD]@imap.gmail.com/INBOX,其中APP_PASSWORD 我无法向您展示,因为那是我根据这些 GMail 建议配置的。
    【解决方案2】:

    感谢阿特姆!有效。实际上,当它是@gmail.com 时。 IMAP URL 中不需要此后缀 - 只需您的帐户即可。例如我连接的时候是这样的:

    imaps://clericsmail:[APP_PASSWORD]@imap.gmail.com/INBOX
    

    APP_PASSWORD 我不能告诉你,因为那是我根据那些 GMail 建议配置的。

    【讨论】:

      猜你喜欢
      • 2011-09-30
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      相关资源
      最近更新 更多