我们无法使用假冒代表发件人取消会议。我们已在用户级别提供代理访问权限。还在交换服务器级别给予模仿权限。仍然当我们尝试从我的邮箱绑定发件人的原始会议ID时,我获得访问被拒绝的异常。我们似乎缺少一些API代码。
任何解决方案都会有很大的帮助。
这是我的代码,
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static string _recipientEmail = "elisabettas@contoso.com";
static string _forwarderEmail = "bobk@contoso.com";
static ExchangeService _senderCalendarExchangeService = ConnectExchangeServer("arleneh@contoso.com", "password"); // Meeting Sender - Originator
static ExchangeService _forwarderCalendarExchangeService = ConnectExchangeServer(_forwarderEmail, "password"); // Meeting Forwarder - First receiver of the meeting who just forwards it.
static void Main(string[] args)
{
// Sender creates a meeting invite & sends it to Forwarder.
Appointment senderAppointment = new Appointment(_senderCalendarExchangeService);
senderAppointment.RequiredAttendees.Add(new Attendee { Address = _forwarderEmail });
senderAppointment.Subject = Guid.NewGuid().ToString();
senderAppointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
// Forwarder scans the meeting invite from its Inbox.
MeetingMessage senderMeetingMessage = GetSenderMeeting(senderAppointment.Subject);
// Fills all default properties.
senderMeetingMessage.Load();
// Converts MeetingMessage object received in Mailbox to its equivalent appointment object in Calendar.
Appointment appointment = Appointment.Bind(_forwarderCalendarExchangeService, senderMeetingMessage.AssociatedAppointmentId);
// Finally, Forwarder forwards it.
ResponseMessage responseMessage = appointment.CreateForward();
responseMessage.ToRecipients.Add(_recipientEmail);
responseMessage.SendAndSaveCopy();
// Now, Sender sends an update to this meeting invite.
senderAppointment = Appointment.Bind(_senderCalendarExchangeService, senderAppointment.Id);
senderAppointment.Subject = Guid.NewGuid().ToString();
senderAppointment.Update(ConflictResolutionMode.AlwaysOverwrite);
// Forwarder again scans the updated meeting invite from its Inbox & forwards it.
senderMeetingMessage = GetSenderMeeting(senderAppointment.Subject);
// However this as subject has changed it has to send cancellation to end recipient.
// Fills all default properties.
senderMeetingMessage.Load();
// Impersonate as sender in order to perform cancel meeting from its calendar.
_forwarderCalendarExchangeService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, senderMeetingMessage.Sender.Address);
// At this line it throughs ServiceResponseException - Access is denied. Check credentials and try again.
appointment = Appointment.Bind(_forwarderCalendarExchangeService, senderMeetingMessage.AssociatedAppointmentId);
appointment.CancelMeeting();
}
static ExchangeService ConnectExchangeServer(string emailAddress, string password)
{
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
exchangeService.Credentials = new WebCredentials(emailAddress, password);
exchangeService.AutodiscoverUrl(emailAddress);
return exchangeService;
}
static MeetingMessage GetSenderMeeting(string senderAppointmentSubject)
{
SearchFilter.IsEqualTo senderMeetingMessageSearchBySubject = new SearchFilter.IsEqualTo(MeetingMessageSchema.Subject, senderAppointmentSubject);
FindItemsResults<Item> senderMeetingRequestResult = _forwarderCalendarExchangeService.FindItems(WellKnownFolderName.Inbox, senderMeetingMessageSearchBySubject, new ItemView(1));
MeetingMessage senderMeetingMessage = senderMeetingRequestResult.First() as MeetingMessage;
senderMeetingMessage.Load();
return senderMeetingMessage;
}
}
}
答案 0 :(得分:0)
在我看来,就像你冒充发件人一样,但是你访问Forwarders邮箱(使用模拟发件人凭证),因此你会收到错误。
你应该这样做
appointment = Appointment.Bind(_forwarderCalendarExchangeService, senderAppointment.Id);
appointment.CancelMeeting();
使用
senderMeetingMessage.AssociatedAppointmentId
将链接到senderMeetingMessage所在的邮箱中的Calendar对象,在您的情况下是转发邮箱。
干杯 格伦