Java Exchange发送邮件
1、Pom依赖引用
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
2、配置文件配置邮箱基本信息
sendUrl=xx.xx.xx.xx
sendMail=xx@xx.com
sendPass=密码
3、方法使用实例
//设置正文
StringBuffer theMessage = new StringBuffer();
//设置具体正文内容
theMessage.append("<span style='width:100%;display:inline-block;text-align:center; font-family:宋体; font-size:29px; font-weight:bold'>xxxxxx</span>");
theMessage.append("<br>");
theMessage.append("<br>");
ExchangeService service = new ExchangeService();
service.setUrl(new URI(PropertyConstants.getPropertiesKey("sendUrl")));
String userName = PropertyConstants.getPropertiesKey("sendMail");
String password = PropertyConstants.getPropertiesKey("sendPass");
service.setCredentials(new WebCredentials(userName, password));
service.setTraceEnabled(true);
EmailMessage message = new EmailMessage(service);
//设置主题,title 为 String 类型
message.setSubject(title);
message.setBody(new MessageBody(BodyType.HTML, theMessage.toString()));
//循环赋值收件人to 为收件人
message.getToRecipients().add(to);
//循环赋值收件人cc 为抄送人
message.getCcRecipients().add(cc);
message.save();
message.sendAndSaveCopy();