我正在尝试阅读来自微软交换服务器的电子邮件,所以我向管理员索取了详细信息,他并不完全确定但是给了我这些细节,
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/