我正在尝试阅读来自 microsoft exchange server 的电子邮件,所以我向管理员询问了详细信息,他并不完全确定,但给了我这些详细信息,
ab-mbx01 = server
ag 07 = storage group
ab-mbx01 DB01 S1000 = Database/DatabaseName
ab-mbx01.de.domain.com = mailbox server.
所以我使用邮箱服务器作为主机并尝试使用 EWS java api 进行连接,但我收到错误说连接被拒绝。
谁能告诉我,我应该使用在代码中插入其他详细信息以及如何在代码中插入它们吗?
谢谢你。
代码:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("username", "password");
service.setCredentials(credentials);
service.setUrl(new java.net.URI("https://" + "mailbox server"
+ "/EWS/Exchange.asmx"));
service.setTraceEnabled(true);
//IF connected view items
ItemView view = new ItemView(10);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
view.setPropertySet(new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject,
ItemSchema.DateTimeReceived));
FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, new SearchFilter.SearchFilterCollection(
LogicalOperator.Or, new SearchFilter.ContainsSubstring(ItemSchema.Subject, "EWS"),
new SearchFilter.ContainsSubstring(ItemSchema.Subject, "API")),view);
System.out.println("Total number of items found: " + findResults.getTotalCount());
for (Item item : findResults)
{
System.out.println(item.getSubject());
System.out.println(item.getBody());
// Do something with the item.
}
使用 JavaMail Api 我使用了相同的代码
http://www.javaplex.com/blog/using-javamail-api-read-emails-from-gmail/