私は、機能の 1 つが Web アプリケーションからアプリケーションにログインしているユーザーの Outlook カレンダーにイベント/予定を設定することである Web アプリケーションに取り組んでいます。この機能をカバーするために EWS マネージ API を使用しています。これは localhost では正常に動作していますが、IIS にアプリケーションを展開すると、Outlook カレンダーで予定/イベントが作成されません。これについて検索しましたが、いくつかの権限が原因で発生している可能性があります。EWS は上記の機能を実現するための適切な API ですか、それとも間違った方法をとっていますか?
親切に解決策を提案してください。
EWSコード
private static ExchangeService Service
{
get
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
//service.Credentials = new WebCredentials("example@abc.com", password);
service.AutodiscoverUrl("example@abc.com");
return service;
}
}
private void SaveAppointment()
{
IAppointmentFactory iappointment = new AppointmentFactory();
List<string> lstEmail = new List<string>() {"other@abc.com"};
CreateAppointments(Service, lstEmail, iappointment);
}
private static void CreateAppointments(ExchangeService service, List<string> emailAddresses, IAppointmentFactory factory)
{
// Loop through the list of email addresses to add the appointment.
foreach (var emailAddress in emailAddresses)
{
Console.WriteLine(string.Format(" Placing appointment in calendar for {0}.", emailAddress));
// Set the email address of the account to get the appointment.
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailAddress);
// Get the appointment to add.
Microsoft.Exchange.WebServices.Data.Appointment appointment = factory.GetAppointment(service);
// Save the appointment.
try
{
Mailbox primary = new Mailbox(emailAddress);
Microsoft.Exchange.WebServices.Data.Folder primaryCalendar = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, primary));
appointment.Save(primaryCalendar.Id, SendInvitationsMode.SendToAllAndSaveCopy);
}
catch (ServiceResponseException ex)
{
Console.WriteLine(string.Format("Could not create appointment for {0}", emailAddress));
Console.WriteLine(ex.Message);
}
}
}