[英]using javaMail to read shared mailbox
I am creating an interface capable of reading e-mails from a shared mailbox. 我正在创建一个能够从共享邮箱中读取电子邮件的界面。 I have already tried several different approaches I could find in stack over, but none worked.
我已经尝试过几种可以在堆栈中找到的不同方法,但是没有一种有效。 Examples:
例子:
Properties props = System.getProperties();
// Set manual Properties
props.setProperty("mail.imaps.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.port", "993");
props.setProperty("mail.imaps.socketFactory.port", "993");
props.put("mail.imaps.host", "outlook.office365.com");
try {
/* Create the session and get the store for read the mail. */
Session session = Session.getDefaultInstance(System.getProperties(), null);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "eduardo.david@hpe.com/APSDataExtract", "-myPassword-");
gives me the following result: 给我以下结果:
Exception while connecting to server: AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661)
at javax.mail.Service.connect(Service.java:295)
at t2.OutLookReader_imaps.<init>(OutLookReader_imaps.java:39)
at t2.OutLookReader_imaps.main(OutLookReader_imaps.java:121)
If I try other codes, the result is the same: 如果我尝试其他代码,结果是一样的:
store.connect("outlook.office365.com", 993, "hpe\\eduardo.david@hpe.com\\APSDataExtract", "-myPassword-");
Result: 结果:
Exception while connecting to server: * BYE Connection is closed. 13
javax.mail.MessagingException: * BYE Connection is closed. 13;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE Connection is closed. 13
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:668)
at javax.mail.Service.connect(Service.java:295)
at t2.OutLookReader_imaps.<init>(OutLookReader_imaps.java:39)
at t2.OutLookReader_imaps.main(OutLookReader_imaps.java:121)
Caused by: com.sun.mail.iap.ConnectionException: * BYE Connection is closed. 13
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:356)
at com.sun.mail.imap.protocol.IMAPProtocol.authplain(IMAPProtocol.java:603)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:736)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:642)
... 3 more
store.connect("outlook.office365.com", 993, "hpe\\eduardo.david\\APSDataExtract", "-myPassword-");
Result: 结果:
Inside MailReader()...
Exception while connecting to server: * BYE Connection is closed. 13
javax.mail.MessagingException: * BYE Connection is closed. 13;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE Connection is closed. 13
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:668)
at javax.mail.Service.connect(Service.java:295)
at t2.OutLookReader_imaps.<init>(OutLookReader_imaps.java:39)
at t2.OutLookReader_imaps.main(OutLookReader_imaps.java:121)
Caused by: com.sun.mail.iap.ConnectionException: * BYE Connection is closed. 13
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:356)
at com.sun.mail.imap.protocol.IMAPProtocol.authplain(IMAPProtocol.java:603)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:736)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:642)
store.connect("outlook.office365.com", 993, "hpe\\davidedu\\APSDataExtract", "-myPassword-");
Result: 结果:
Inside MailReader()...
Exception while connecting to server: * BYE Connection is closed. 13
javax.mail.MessagingException: * BYE Connection is closed. 13;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE Connection is closed. 13
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:668)
at javax.mail.Service.connect(Service.java:295)
at t2.OutLookReader_imaps.<init>(OutLookReader_imaps.java:39)
at t2.OutLookReader_imaps.main(OutLookReader_imaps.java:121)
Caused by: com.sun.mail.iap.ConnectionException: * BYE Connection is closed. 13
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:356)
at com.sun.mail.imap.protocol.IMAPProtocol.authplain(IMAPProtocol.java:603)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:736)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:642)
... 3 more
To access my own inbox, code works perfectly: 要访问我自己的收件箱,代码可以完美运行:
store.connect("outlook.office365.com", 993, "eduardo.david@hpe.com", "-myPassword-");
Inside MailReader()... No. of Unread Messages : 580 No. of Messages : 849 No. of Deleted Messages : 2 Inside MailReader()...未读邮件数:580邮件数:849删除邮件数:2
Can anybody give to this java new programmer a simple solution in order to read a shared mailbox? 有人可以给这个Java新程序员一个简单的解决方案,以读取共享邮箱吗?
I solved it adding this parameters: 我添加了以下参数来解决它:
sysProps.setProperty("mail.imaps.auth.plain.disable", "true");
sysProps.setProperty("mail.imaps.auth.ntlm.disable", "true");
I connected using: 我连接使用:
store.connect("outlook.office365.com", "name@abc.com\\sharedmailAlias", "password");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.