0

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("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);
    }
   }
  }
manika
  • 187
  • 2
  • 13

1 Answers1

0

Your application and IIS need to be specifically configured to allow delegation of the credentials to work see https://blogs.msdn.microsoft.com/emeamsgdev/2012/11/05/ews-from-a-web-application-using-windows-authentication-and-impersonation/

Glen Scales
  • 20,495
  • 1
  • 20
  • 23