简单示例:
package com.aires;
import java.net.URI;
import microsoft.exchange.webservices.data.EmailMessage;
import microsoft.exchange.webservices.data.EmailMessageSchema;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.ExchangeVersion;
import microsoft.exchange.webservices.data.FindItemsResults;
import microsoft.exchange.webservices.data.Folder;
import microsoft.exchange.webservices.data.ItemView;
import microsoft.exchange.webservices.data.SearchFilter;
import microsoft.exchange.webservices.data.WebCredentials;
import microsoft.exchange.webservices.data.WellKnownFolderName;
public class Test {
public static void main(String[] args) throws Exception{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ExchangeCredentials credentials = new WebCredentials("邮箱账号", "密码");
service.setCredentials(credentials);
service.setUrl(new URI("http://xxxx/a/b?wsdl"));//服务地址
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);//收件箱
System.out.println("未读邮件数:" + inbox.getUnreadCount());
ItemView view = new ItemView(10);
view.setOffset(view.getOffset());
FindItemsResults<microsoft.exchange.webservices.data.Item> findResults = service
.findItems(inbox.getId(),new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false), view);
for (microsoft.exchange.webservices.data.Item item : findResults
.getItems()) {
EmailMessage message = EmailMessage.bind(service, item.getId());
System.out.print(message.getSender().toString() + ": " + item.getSubject());
}
}
}
java获取Exchange未读邮件
最新推荐文章于 2023-12-21 14:29:18 发布