What exists:
A web app that allows a user to create an appointment, input the required attendees, and send the appointment request.
What I want to happen:
My web app to send an appointment request (on behalf of the user who is using the web app) to multiple recipients via EWS. Avoiding EWS's impersonation option
What I've tried:
Dim service As New ExchangeService(TimeZoneInfo.FindSystemTimeZoneById(sNewEmpTZ))
service.Url = New Uri("https://exchange.url")
Dim cred As NetworkCredential = CredentialCache.DefaultNetworkCredentials
service.Credentials = cred
Dim app As Appointment = New Appointment(service)
'build required body, subject, attendees, location, time, date etc.
app.Save(SendInvitationsMode.SendToAllAndSaveCopy)
What's Happening:
When I run this app through my localhost, it works flawlessly - will get the cached credentials under the current user (me) and send the appointment request. When I roll this code out to our dev server, I get the following error message after the code tries to send the appointment (app.Save(...)):
Error: When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.
Which tells me that the code isn't able to get the current user's credentials. Note: our dev server is using Kerberos for authentication, which is why I thought the code should work.
What I've Researched:
I have been looking at this error message for the past two days and I haven't been able to find a similar situation that has a solution.
What else have I tried:
I know that CredentialCache.DefaultCredentials
is essentially equivalent, so I did try
Dim service As New ExchangeService(TimeZoneInfo.FindSystemTimeZoneById(sNewEmpTZ))
service.Url = New Uri("https://exchange.url")
Dim cred As ICredentials = CredentialCache.DefaultCredentials
service.Credentials = cred
Dim app As Appointment = New Appointment(service)
'build required body, subject, attendees, location, time, date etc.
app.Save(SendInvitationsMode.SendToAllAndSaveCopy)
But I will get the following error for both local and dev:
Unable to cast object of type 'System.Net.SystemNetworkCredential' to type 'Microsoft.Exchange.WebServices.Data.ExchangeCredentials'.
My question:
Knowing that our dev server is set up to use Kerberos protocol, and the user is windows authenticated, why wouldn't CredentialCache.DefaultNetworkCredentials
be able to gather the current user's credentials?
Disclaimer:
I'm very new to how windows authentication is actually working. Also, before similar stack overflow questions get posted, I've already reviewed the following two that seemed to relate to my problem the most.
- http://stackoverflow.com/questions/12851705/ad-user-authentication
- http://stackoverflow.com/questions/949340/getting-networkcredential-for-current-user-c