0
votes

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);
    }
   }
  }
1
Does someone has any idea about this issue?manika
Glen Scales is propably right, but to confirm this (and provide further help), we'd need to see your code.NotTelling
Now you can see my code too. I am stuck with this issue.manika

1 Answers

0
votes

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/