gpt4 book ai didi

JavaMail - 阅读 Outlook 邮件时出现 AuthenticationFailedException

转载 作者:行者123 更新时间:2023-12-01 18:36:55 25 4
gpt4 key购买 nike

我正在使用下面的代码使用 Java mail 1.6.2 阅读 Outlook 电子邮件

          Properties props = new Properties();        
props.setProperty("mail.imap.ssl.enable", "true");
Session mailSession = Session.getInstance(props);
mailSession.setDebug(true);
Store mailStore = mailSession.getStore("imap");
mailStore.connect("outlook.office365.com", "abc@company.com", "password");

但是,即使登录凭据正确,我也会遇到以下错误。请查找以下日志:

DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [TQBBADEAsomeText]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: XOAUTH2
DEBUG IMAP: protocolConnect login, host=outlook.office365.com, user=abc@company.com, password=<non-null>
DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 NO AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732)
at javax.mail.Service.connect(Service.java:366)
at javax.mail.Service.connect(Service.java:246)

知道原因是什么吗?

最佳答案

问题是主机错误!将 Outlook.office365.com (imap-mail.outlook.com) 替换为公司特定主机并且它有效!

mailStore.connect("mail.ad.company.com", "abc@company.com", "password"); 

关于JavaMail - 阅读 Outlook 邮件时出现 AuthenticationFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60016057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com