// Adds a delegate to the primary email account that receives calendar requests // and has permission to edit the primary email account's calendar. static void AddCalendarEditDelegate(ExchangeService service, Mailbox primaryMailbox, string delegateEmailAddress) { DelegateUser calendarDelegate = new DelegateUser(delegateEmailAddress); calendarDelegate.ReceiveCopiesOfMeetingMessages = true; calendarDelegate.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor; service.AddDelegates(primaryMailbox, MeetingRequestsDeliveryScope.DelegatesAndMe, calendarDelegate); }
/// <summary> /// 授权代理人 /// </summary> /// <param name="config"></param> /// <returns></returns> public static Collection <DelegateUserResponse> AddDelegates(ExchangeAdminConfig config) { InitializeEws(config); // Create a list to hold the new delegates to add. List <DelegateUser> newDelegates = new List <DelegateUser>(); //创建一个新的代理,该代理具有邮箱所有者日历文件夹的编辑器访问权限。. DelegateUser calendarDelegate = new DelegateUser("*****@*****.**"); calendarDelegate.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor; // Add the delegate to the list of new delegates. newDelegates.Add(calendarDelegate); // 创建具有邮箱所有者的“联系人”文件夹的编辑者访问权限的新代理。 DelegateUser contactDelegate = new DelegateUser("*****@*****.**"); contactDelegate.Permissions.ContactsFolderPermissionLevel = DelegateFolderPermissionLevel.Editor; // Add the delegate to the list of new delegates. newDelegates.Add(contactDelegate); // 创建具有对邮箱所有者的收件箱文件夹的编辑者访问权限的新代理。 DelegateUser emailDelegate = new DelegateUser("*****@*****.**"); emailDelegate.Permissions.InboxFolderPermissionLevel = DelegateFolderPermissionLevel.Editor; // Add the delegate to the list of new delegates. newDelegates.Add(emailDelegate); // 创建表示邮箱所有者的邮箱对象。 Mailbox mailbox = new Mailbox("*****@*****.**"); // Call the AddDelegates method to add the delegates to the target mailbox. Collection <DelegateUserResponse> response = Service.AddDelegates(mailbox, MeetingRequestsDeliveryScope.DelegatesAndSendInformationToMe, newDelegates); foreach (DelegateUserResponse resp in response) { // Print out the result and the last eight characters of the item ID. Console.WriteLine("For delegate " + resp.DelegateUser.UserId.PrimarySmtpAddress.ToString()); Console.WriteLine("Result: {0}", resp.Result); Console.WriteLine("Error Code: {0}", resp.ErrorCode); Console.WriteLine("ErrorMessage: {0}\r\n", resp.ErrorMessage); Console.WriteLine("\r\n"); } return(response); }
public void AddDelegate(string delegateSmtp, bool receiveSchedulers, bool viewPrivateItems, string currentSchedulerOption) { MeetingRequestsDeliveryScope scope = (MeetingRequestsDeliveryScope)Enum.Parse(typeof(MeetingRequestsDeliveryScope), currentSchedulerOption); DelegateUser delegateUser = new DelegateUser(delegateSmtp); delegateUser.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor; delegateUser.ReceiveCopiesOfMeetingMessages = receiveSchedulers; delegateUser.ViewPrivateItems = viewPrivateItems; Collection <DelegateUserResponse> result = service.AddDelegates(mailbox, scope, delegateUser); if (result[0].Result == ServiceResult.Success) { return; } else { throw new EWSException(result[0].ErrorCode.ToString(), result[0]); } }