private ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
public EWService(String email, String userPwd) throws Exception {
ExchangeCredentials credentials = new WebCredentials(email, userPwd);
service.setCredentials(credentials);
service.setUrl(new URI("https://XXX/ews/Exchange.asmx"));
}
/*
* 寄信測試
*/
public void sendmailTest() throws Exception {
EmailMessage msg = new EmailMessage(service);
msg.setSubject("Hello world! 哈囉 ~ 世界");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Managed API. 由 微軟提供 java api 測試發送"));
msg.getToRecipients().add("test@test.test");
msg.send();
}
完整 EWS API 說明和 sample at http://msdn.microsoft.com/en-us/library/exchange/dd633696(v=exchg.80)
沒有留言:
張貼留言