IMAP에서 Hotmail로부터 전자 메일을 받고 싶지만 OAuth가 인증해야합니다. Microsoft의 문서에서 지원하는 내용은 http://msdn.microsoft.com/en-us/library/dn440163.aspx입니다.IMAP 및 OAuth를 통해 hotmail에서 이메일을받는 방법은 무엇입니까?
하지만 Java (Javamail 제공)에서 사용하는 방법을 알아야합니다. Google 코드 샘플 (올바른 이메일 및 access_toket)을 사용해 보았지만 실패했습니다.
String email = "[email protected]";
String oauthToken = "XXXXXXXX";
initialize();
IMAPStore imapStore = connectToImap("imap-mail.outlook.com",
993,
email,
oauthToken,
true);
System.out.println("Successfully authenticated to IMAP.\n");
Folder folder = imapStore.getDefaultFolder();
folder.open(Folder.READ_ONLY); //****The linke throw exception****
for (Message msg : folder.getMessages()) {
String subject = msg.getSubject();
System.out.println(":" + subject);
}
시스템 콘솔에 인쇄 된 로그는,
DEBUG: setDebug: JavaMail version 1.4
DEBUG: mail.imap.fetchsize: 16384
DEBUG: enable SASL
DEBUG: SASL mechanisms allowed: XOAUTH2
* OK Outlook.com IMAP4rev1 server version 17.4.0.0 ready (DUB451-IMAP183)
A0 CAPABILITY
* CAPABILITY IMAP4rev1 CHILDREN ID NAMESPACE UIDPLUS UNSELECT AUTH=PLAIN AUTH=XOAUTH2 SASL-IR
A0 OK CAPABILITY completed
IMAP DEBUG: AUTH: PLAIN
IMAP DEBUG: AUTH: XOAUTH2
DEBUG: protocolConnect login, host=imap-mail.outlook.com, [email protected], password=<non-null>
IMAP SASL DEBUG: Mechanisms: XOAUTH2
IMAP SASL DEBUG: SASL client XOAUTH2
A1 AUTHENTICATE XOAUTH2
+
IMAP SASL DEBUG: challenge: :
IMAP SASL DEBUG: callback length: 1
IMAP SASL DEBUG: callback 0: [email protected]
IMAP SASL DEBUG: response: [email protected]=Bearer
DEBUG: connection available -- size: 1
A2 EXAMINE ""
A1 NO [AUTHENTICATIONFAILED] OAuth authentication failed.
A2 BAD Examine Command is not permitted in current state (NotAuthenticated)
A3 LOGOUT
* BYE Logout requested
Exception in thread "main" javax.mail.MessagingException: A2 BAD Examine Command is not permitted in current state (NotAuthenticated);
nested exception is:
com.sun.mail.iap.BadCommandException: A2 BAD Examine Command is not permitted in current state (NotAuthenticated)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:829)
at com.google.code.samples.oauth2.OAuth2Authenticator.main(OAuth2Authenticator.java:155)
Caused by: com.sun.mail.iap.BadCommandException: A2 BAD Examine Command is not permitted in current state (NotAuthenticated)
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:296)
at com.sun.mail.imap.protocol.IMAPProtocol.examine(IMAPProtocol.java:636)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:811)
... 1 more
섹션 1의 답변이 hotmail에서 작동하고 있습니까? –
@matant 네, 여전히 작동 중입니다. 핫메일 계정을 사용하지 않았습니다. – Stony
범위 wl.imap 및 wl.offline_access는 어떻게 사용합니까? 그것은 내 자바 코드의 일부가되어야합니까? –