EWS java api 向Exchange 服务器中创建日历会议
EWS java api 向Exchange 服务器中删除日历会议
通过会议管理系统将客户会议信息发送到Exchange 服务系统日历中.
有小伙伴留言怎么添加附件,于是我在代码中补充了添加附件的代码.
我写了个工具类如下:
pom.xml
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
* Exchange 发送一条会议邮件
public static String sendEws(MeetTaskDTO meetTaskDTO) {
String sendEwsId = "";
MeetTaskEwsDto meetTaskEwsDto = transferMeetTaskDTO2MeetTaskEwsDTO(meetTaskDTO);
MailField mailField = MailUtils.getMailField(meetTaskDTO.getTenantId());
String exchangeversion = StringUtils.isNotEmpty(mailField.getExchangeVersion()) ?mailField.getExchangeVersion() : MailConfig.getDefaultMailField().getExchangeVersion();
try {
ExchangeService service = new ExchangeService(ExchangeVersion.valueOf(exchangeversion));
String serverHost = mailField.getExchangeServeHost();
ExchangeCredentials credentials = new WebCredentials(mailField.getExchangeAccount(), mailField.getExchangePwd());
service.setCredentials(credentials);
service.setUrl(new URI("https://" + serverHost + "/ews/exchange.asmx"));
service.setCredentials(credentials);
service.setTraceEnabled(true);
TimeZoneDefinition tz = getTimeZoneDefinition(service, "UTC+08:00");
Appointment appointment = new Appointment(service);
appointment.setSubject(meetTaskEwsDto.getTaskName());
appointment.setBody(MessageBody.getMessageBodyFromText(meetTaskEwsDto.getContent()));
appointment.setStart(meetTaskEwsDto.getTaskStartTime());
appointment.setStartTimeZone(tz);
appointment.setEnd(meetTaskEwsDto.getTaskEndTime());
appointment.setEndTimeZone(tz);
appointment.setLocation(meetTaskEwsDto.getRoomName());
**
if(StringUtils.isNotEmpty(meetTaskEwsDto.getParticipantsnEmail())){
for(String mail:meetTaskEwsDto.getParticipantsnEmail()){
appointment.getRequiredAttendees().add(mail);
appointment.save(WellKnownFolderName.Calendar);
sendEwsId = appointment.getId().toString();
} catch (Exception e) {
e.printStackTrace();
return sendEwsId;
* 获取时区
* @param service
* @param timeZoneID
* @return
private static TimeZoneDefinition getTimeZoneDefinition(ExchangeService service, String timeZoneID) {
TimeZoneDefinition timeZoneDefinition = null;
try {
for (TimeZoneDefinition tzd : service.getServerTimeZones()) {
if(tzd.getId().equalsIgnoreCase(timeZoneID)) {
timeZoneDefinition = tzd;
break;
} catch (Exception e) {
e.printStackTrace();
return timeZoneDefinition;
* 封装数据
* @param meetTaskDTO
* @return
* meetTaskDTO 是传过来的对象
private static MeetTaskEwsDto transferMeetTaskDTO2MeetTaskEwsDTO(MeetTaskDTO meetTaskDTO) {
MeetTaskEwsDto meetTaskEwsDto =new MeetTaskEwsDto();
meetTaskEwsDto.setTaskName(meetTaskDTO.getTaskName());
meetTaskEwsDto.setRoomName(meetTaskDTO.getRoomName());
meetTaskEwsDto.setContent(meetTaskDTO.getContent());
//拼接开始时间和结束时间
String taskStartTime = meetTaskDTO.getTaskDate()+" "+meetTaskDTO.getTaskStartTime();
String taskEndTime = meetTaskDTO.getTaskDate()+" "+meetTaskDTO.getTaskEndTime();
meetTaskEwsDto.setTaskStartTime(DateUtils.allStringToDate (taskStartTime));
meetTaskEwsDto.setTaskEndTime(DateUtils.allStringToDate(taskEndTime));
//通过任务id 查询参与人员对象信息
//由于静态工具类无法注入 这个是获取 bean
MeetTaskPersonService meetTaskPersonService = SpringUtils.getBean(MeetTaskPersonService.class);
List<MeetTaskPersonDTO> meetTaskPersonDTOS = meetTaskPersonService.listEmployeeParticipatesByTaskId(meetTaskDTO.getId());
meetTaskDTO.setEParticipates(meetTaskPersonDTOS);
//将参与人集合对象 转换成userid 集合
List<String> personIdList = meetTaskDTO.getEParticipates().stream().map(MeetTaskPersonDTO::getPersonId).collect(Collectors.toList());
//判断参会人员是否有发起人 如果不包含就添加
if(!personIdList.contains(meetTaskDTO.getCreateUser())){
personIdList.add(meetTaskDTO.getCreateUser());
//获取用户邮箱
List<String> mails = new ArrayList<>();
UserService userService = SpringUtils.getBean(UserService.class);
for (String personId:personIdList){
//由于是工具 这个是获取 bean
UserDTO userDto = userService.getUserById(personId).getData();
mails.add(userDto.getEmail());
meetTaskEwsDto.setParticipantsnEmail(mails);
return meetTaskEwsDto;
如果有小伙伴觉得不够详细具体可看官方网址:
https://docs.microsoft.com/zh-cn/exchange/client-developer/exchange-web-services/how-to-add-attachments-by-using-ews-in-exchange
欢迎大家留言讨论
如有转载请标明出处
通过会议管理系统将客户会议信息发送到Exchange 服务系统日历中.我写了个工具类如下:pom.xml <dependency> <groupId>com.microsoft.ews-java-api</groupId> <artifactId>ews-java-api</artifactId> <version>2.0</version>
1. Microsoft Exchange Server简介
Microsoft Exchange Server 是个消息与协作系统。Exchange server可以被用来构架应用于企业、学校的邮件系统或免费邮件系统。
Exchange Server主要版本有2003,2007,2010,2013以及云环境的Exchange Online。
我们主要与Exchange Server进行互动
public class Test1 {
public static void main(String[] args) {
sendMeetingInvitationEmail();
private static Properties props;
private static Session session;
public static void sendMeetingInvitationEmail() {
try {
Spring Boot Starter Mail和EWS Java API都是用于发送电子邮件的Java库,但它们有以下区别:
1. Spring Boot Starter Mail是Spring Boot框架内置的邮件发送组件,提供了简单易用的API,可以轻松地配置和发送电子邮件。而EWS Java API是Microsoft Exchange Web Services(EWS)的Java实现,主要用于与Exchange服务器进行通信。
2. Spring Boot Starter Mail支持多个邮件协议,如SMTP、SMTPS、IMAP和IMAPS,而EWS Java API仅支持与Exchange服务器进行通信。
3. Spring Boot Starter Mail可以在不需要任何额外配置的情况下快速启动,而EWS Java API需要进行一些配置才能使用。
4. Spring Boot Starter Mail提供了一些简单的邮件模板渲染功能,可以方便地生成HTML邮件内容,而EWS Java API则没有提供类似的功能。
因此,如果只是发送普通的电子邮件,建议使用Spring Boot Starter Mail;如果需要与Exchange服务器进行通信,或者需要更高级的功能,可以考虑使用EWS Java API。
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)
19000