1
votes

I've got a small bit of code that connects to Exchange to get the appointments for a particular account. This account does not have a mailbox.

Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP2)
service.Credentials = New NetworkCredential("userID", "password")
service.AutodiscoverUrl("[email protected]")   

Dim calView As New CalendarView(DateTime.Today, DateTime.Today.AddYears(2))
calView.Traversal = ItemTraversal.Shallow
calView.PropertySet = New PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Subject, AppointmentSchema.Location)

Dim mtgs As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Calendar, calView)

The code raises the following exception on the last line.

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.

I've run the code with service.UseDefaultCredentials = True in place of the Credentials line and it executes but brings back my appointments, of course. Is there a fix for this? I think my alternative is to convince the Exchange admins to grant my account Impersonate privileges for the account of interest.

1
Consider posting your answer, as an answer. It'll help out other users.Idris

1 Answers

1
votes

I found my error. This account has rights to the schedules for some meeting rooms but doesn't have a mailbox (or calendar) of its own. Therefore the FindItems line should not use "WellKnowFolderName.Calendar", which would be the calendar of the account. Instead, it should use a new FolderID object that specifies the calendar folder for the meeting room being searched.

Dim _cal As New FolderId(WellKnownFolderName.Calendar, New Microsoft.Exchange.WebServices.Data.Mailbox(room))