EWS send mail meeting, read meeting message(二)

本文介绍如何使用Microsoft Exchange Web Services (EWS) API创建、更新和取消会议请求。通过C#代码示例展示了如何设置会议属性,如主题、时间、地点以及参与者,并演示了如何更新会议时间和主题,以及最终取消会议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3.Send  update  cancel  meeting 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using vBooking.Utility;
using Microsoft.Exchange.WebServices.Data;

namespace EWSSendEmailConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                CreateMeeting(Service());

                Console.WriteLine("OK");
            }
            catch(System.Exception ex)
            {
                Console.WriteLine(ex);
            }

        }


        private static ExchangeService Service()
        {
            ExchangeService service = new ExchangeService();
            service.Credentials = new WebCredentials(WebConfig.GetString("Usercount"), WebConfig.GetString("pwd"));
            service.Url = new Uri(WebConfig.GetString("ExchangeUrl"));
            Console.WriteLine(service.Url);

            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, WebConfig.GetString("From"));

           
            return service;

        }

        private static void CreateMeeting(ExchangeService service)
        {

            Appointment meeting = new Appointment(service);
            // Set the properties on the meeting object to create the meeting. 
            meeting.Subject = WebConfig.GetString("Subject");
            meeting.Body = WebConfig.GetString("Body");
            meeting.Start = Convert.ToDateTime(WebConfig.GetString("StartTime"));
            meeting.End = Convert.ToDateTime(WebConfig.GetString("EndTime"));
            meeting.Location = WebConfig.GetString("Location");


            var RequiredList = WebConfig.GetString("RequiredAttendees");
            if (!string.IsNullOrEmpty(RequiredList))
            {
                var list = RequiredList.Split(';');

                for (var i = 0; i < list.Count(); i++)
                {
                    meeting.RequiredAttendees.Add(list[i]);
                    Console.WriteLine($"Required:" + list[i]);
                }

            }
            else
            {
                Console.WriteLine("RequiredAttendees Not Null");
            }

            Console.WriteLine($"OptionalAttendees:{WebConfig.GetString("OptionalAttendees")}");
            meeting.OptionalAttendees.Add(WebConfig.GetString("OptionalAttendees"));
            meeting.ReminderMinutesBeforeStart = 15;
            Console.WriteLine("Start Send");
            // Save the meeting to the Calendar folder and send the meeting request. 
            meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
            Console.WriteLine($"Send End:MeetingID:{meeting.Id}");
        }

        private static void UpdateMeeting(ExchangeService service,string appointmentId)
        {
            Appointment appointment = Appointment.Bind(service, appointmentId, new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));

            string oldSubject = appointment.Subject;

            // Update properties on the appointment with a new subject, start time, and end time.
            appointment.Subject = appointment.Subject + " moved one hour later and to the day after " + appointment.Start.DayOfWeek + "!";
            appointment.Start.AddHours(25);
            appointment.End.AddHours(25);

            // Unless explicitly specified, the default is to use SendToAllAndSaveCopy.
            // This can convert an appointment into a meeting. To avoid this,
            // explicitly set SendToNone on non-meetings.
            SendInvitationsOrCancellationsMode mode = appointment.IsMeeting ?
                SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy : SendInvitationsOrCancellationsMode.SendToNone;

            // Send the update request to the Exchange server.

            appointment.Update(ConflictResolutionMode.AlwaysOverwrite, mode);
        }

        private static void CancelMeeting(ExchangeService service, string appointmentId)
        {

            //get the appointment based on the appointment ID
            Appointment appointment = Appointment.Bind(service, new ItemId(appointmentId));

            //cancel the appointment
            appointment.CancelMeeting();

            //Set it back to null so that any actions that will be taken using the exchange service
            //applies to impersonating account (i.e.account used in network credentials)
            service.ImpersonatedUserId = null;


        }

    }
}

 

转载于:https://www.cnblogs.com/zrynet/p/8656514.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值