不使用 IMAP 和 POP3 从 office365 收件箱读取电子邮件

Read email from office365 inbox without using of IMAP and POP3

需要在不使用 IMAPPOP3[=17= 的情况下从 office365 收件箱中读取电子邮件] 协议,因为这些协议在我的情况下被禁用,而且由于某些安全问题我无法启用它们。如果没有这两个协议,请建议我是否有其他方法可以做到这一点。

提前致谢!

是的,还有另一种方法(事实上有几种,但我会建议一种)。有一个 API 叫做 EWS (Exchange Web Services)。使用起来非常简单。您只需要帐户的凭据。

这是一个小例子:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); // This is the latest version of this library

ExchangeCredentials credentials = new WebCredentials("email", "password");
service.setCredentials(credentials);
// this.exchangeService.setWebProxy(new WebProxy("xx.xxx.xxx.xx", 8080)); // If you're behind a proxy
service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx")); // This is the standard URL

Folder inboxFolder = Folder.bind(service, WellKnownFolderName.Inbox);

FindItemsResults<Item> results = service.findItems(inboxFolder.getId(), new ItemView(10)); // 10 is the number of items to fetch (pagesize)

for (Item result : results)
{
    EmailMessage currentEmail = (EmailMessage) result;

    System.out.println(currentEmail.getFrom());
    // And so on
}

图书馆可以做更多的事情,例如 reading/booking 约会、发送电子邮件等等。

据我所知,该库使用 SOAP,因此您不会受到 POP 和 IMAP 的影响。