引入maven包:
com.microsoft.ews-java-api
ews-java-api
2.0
使用office 365邮箱服务收发邮件有两种校验方式,一种是老的basic authentication, 这种方式目前已不建议使用,如下使用的是userName, password进行验证的方式。
public static boolean sendExchange(MailConfig mailInfo) {
// The Exchange Server Version.
try (ExchangeService exchangeService = new ExchangeService(exchangeVersion)) {
// Credentials to sign in the MS Exchange Server.
ExchangeCredentials exchangeCredentials = new WebCredentials(ExchangeMailUtil.getUsername(), ExchangeMailUtil.getPassword());
exchangeService.setCredentials(exchangeCredentials);
// URL of exchange web service for the mailbox.
exchangeService.setUrl(new URI("https://outlook.office365.com/ews/exchange.asmx"));
// The email.
EmailMessage emailMessage;
emailMessage = new EmailMessage(exchangeService);
emailMessag