EWS send mail meeting, read meeting message

Posted zrynet

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EWS send mail meeting, read meeting message相关的知识,希望对你有一定的参考价值。

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;


        }

    }
}

 

以上是关于EWS send mail meeting, read meeting message的主要内容,如果未能解决你的问题,请参考以下文章

Send Meeting By SMTP

配置redis集群报错Failed to send CLUSTER MEET command.

配置redis集群报错Failed to send CLUSTER MEET command.

配置redis集群报错Failed to send CLUSTER MEET command.

从 EWS 创建 Outlook 用户属性

django-28.发送邮件send_mail