JAVA 连接
Exchange服务
联合经济委员会提供了一个纯Java API来访问Microsoft Exchange Server。有了它,您可以访问和处理电子
邮件,日历,联系人,并在Exchange服务器任务。它支持2种执照- 1)非利润,学术机构,以及个人,和2)商业。欲了解更多信息请参阅:
http://javaexchangeconnector.googlepages.com这是google快照,里面有不错的事例。简单的连接
String _exchangeHost = "192.168.0.29";
String _applicationUserAccountName = "beijing";
String _applicationUserPassword = "123456";
String _prefix = "Exchange";
boolean _useSSL = false;
String _mailboxName = "beijing";
ExchangeConnectorFactory factory = new ExchangeConnectorFactory("D:/web/www/eclipse-workspace/java_exchange/WEB-INF/lib");
// ExchangeConnectorInterface connector = null;
factory.setPrivkeystoreFullPath("D:/web/www/eclipse-workspace/java_exchange/WEB-INF/lib/privkeystore");
// ExchangeConnectorFactory factory = new ExchangeConnectorFactory();
ExchangeConnectorInterface connector = null;
connector = factory.createExchangeConnector(_exchangeHost,
_applicationUserAccountName,
_applicationUserPassword,
_prefix, _useSSL, _mailboxName);
System.out.println("connector.getDraftsFolderName():"+connector.getDraftsFolderName());
//connector.getEmailFolderName();
System.out.println("connector.getEmailFolderName():"+connector.getEmailFolderName());
try {
// connector.getFolders("http://192.168.0.29/exchange/beijing/%E5%8F%91%E4%BB%B6%E7%AE%B1/");//http://192.168.0.29/exchange/liuwg/%E6%94%B6%E4%BB%B6%E7%AE%B1/
//草稿 %E8%8D%89%E7%A8%BF
//收件箱 %E6%94%B6%E4%BB%B6%E7%AE%B1
//发件箱 %E5%8F%91%E4%BB%B6%E7%AE%B1
//已发送邮件 %E5%B7%B2%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6
connector.setEmailFolderName("%E5%B7%B2%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6");
ArrayList list = connector.getEmails();
System.out.println("########################## Email 有"+list.size()+"条");
for(int i=0; i<list.size(); i++){
ExchangeEmailDTO email = (ExchangeEmailDTO) list.get(i);
System.out.println("email1.getUniqueIdForUrl(): " +
email.getUniqueIdForUrl());
System.out.println("email1.getSubject(): " +
email.getSubject());
// System.out.println("email1.getBody(): " +
// email.getBody());
System.out.println("email1.getDateReceived(): " +
email.getDateReceived());
System.out.println("email1.getTo(): " +
email.getTo());
System.out.println("email1.getFrom(): " +
email.getFrom());
System.out.println("email1.isRead: " +
email.isRead());
System.out.println("email1.getCc: " +
email.getCc());
System.out.println("email1.getBcc: " +
email.getBcc());
System.out.println("----------------------------------------------------------------");
}
} catch (ExchangeGeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}