0
votes

We developed a SharePoint web part that displays selected users's calender items by requesting Exchange OnPrem 2013 or Exchange Online for users that have thier mailbox on Office 365. The code we're using is as follows :

// Impersonate the Search
ExchangeImpersonationType exchangeImpersonationType = new ExchangeImpersonationType();

ConnectingSIDType connectingSIDType = new ConnectingSIDType();
connectingSIDType.PrimarySmtpAddress = emailAddress;
exchangeImpersonationType.ConnectingSID = connectingSIDType;
exchangeServiceBinding.ExchangeImpersonation = exchangeImpersonationType;

// Create the Request
FindItemType findItemType = new FindItemType();

// Specified Transversal
findItemType.Traversal = ItemQueryTraversalType.Shallow;

// Specified ItemShape
ItemResponseShapeType itemResponseShapeType = new ItemResponseShapeType();
itemResponseShapeType.BaseShape = DefaultShapeNamesType.AllProperties;
findItemType.ItemShape = itemResponseShapeType;

// Specified ParentFolderIds
DistinguishedFolderIdType[] distinguishedFolderIdTypes = new DistinguishedFolderIdType[1];
distinguishedFolderIdTypes[0] = new DistinguishedFolderIdType();
distinguishedFolderIdTypes[0].Id = DistinguishedFolderIdNameType.calendar;
findItemType.ParentFolderIds = distinguishedFolderIdTypes;

// Specified Item
CalendarViewType calendarViewType = new CalendarViewType();
calendarViewType.StartDate = startDate;
calendarViewType.EndDate = endDate;

findItemType.Item = calendarViewType;

// Execute the Request
FindItemResponseType res = exchangeServiceBinding.FindItem(findItemType);

The issue is that when user doesn't have a mailbox on Exchange OnPrem, the exchangeServiceBinding.FindItem method answers after 3 to 5 secondes with the error code "UserHasNoMailbox".

Imagine now loading a page with more thant 40 users and having 10 users among them that have mailbox on Exchange Online, we're losing at least 30 secondes in this case.

Is there any way to know if user has mailbox on Exchange OnPrem without making the FindItem request ?

Thanks.

1
Just to clarify, you have some sharepoint list with emails, and you want to look up each email in the on premises Exchange? And if email is on ExchangeOnline do nothing?Mike Twc
Hi Mike, we have a list of users, we get each one's email and check if he got calendar events on Exchange OnPrem, and if not then we try to get his calendar events from Exchange Online.KhalilG

1 Answers

0
votes

Possible work around - you can lookup on premises mailboxes in Active Directory. Here is a power shell snippet (can convert it to C# easily)

$mail = "[email protected]"
([adsisearcher]"(&(objectCategory=person)(objectClass=organizationalPerson)(mail=$mail))").FindOne().Properties

This lookup should be pretty quick ( at least comparing to 3-5 seconds). If you getting any result you can do "FindItem" on premises, if not check it on Exchange Online.

If there is an AD group or Exchange DL all these on premises emails are members of, you can extract list of group members from AD first (instead of running the query above multiple times)