I am working on a web application in which one of the functionality is to set events/appointment from web application to outlook calendar of the user logged in the application. I am using EWS Managed API to cover this functionality. This is working fine on localhost but when I deployed application on IIS then the appointments/events are not being created in outlook calendar. I have searched regarding this and it might be happening due to some permissions. Is EWS the right API to achieve above functionality or I am going in wrong way?
Kindly suggest any solution.
EWS Code
private static ExchangeService Service
{
get
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
//service.Credentials = new WebCredentials("[email protected]", password);
service.AutodiscoverUrl("[email protected]");
return service;
}
}
private void SaveAppointment()
{
IAppointmentFactory iappointment = new AppointmentFactory();
List<string> lstEmail = new List<string>() {"[email protected]"};
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);
}
}
}