Reputation: 20224
Given just an email address, I connect to the Mailbox that receives the emails sent to that address:
ews.autodiscoverUrl(email);
var m = new Mailbox(email);
var folderId = new FolderId(WellKnownFolderName.Inbox, m);
var folder = Folder.Bind(ews,folderId);
Is there a way find out what kind of mailbox I opened - whether it is a user, a resource or a shared mailbox?
Upvotes: 1
Views: 5079
Reputation: 599021
You can find the mailbox type given the email address by calling ResolveName
:
var mailboxes = ews.ResolveName(email);
if (mailboxes.Any()) {
var mailbox = mailboxes.First();
if (mailbox.MailboxType == MailboxType.PublicFolder) {
// your magic
}
}
See this MSDN page for the possible values of the MailboxType.
There is no distinction between a regular mailbox and the mailbox from a room. If you want to know what rooms exist in an Exchange server, you can use the EWS GetRoomLists
and GetRooms
functions.
By combining the snippet above with GetRoomLists
/GetRooms
, you can get the mailbox for a room. But keep in mind: there may be rooms without a mailbox.
The approach using GetRoomLists
/GetRooms
is the only one that will allow you to identify a room's mailbox using EWS. But it does require that you have the rooms added to a room list, which may require you to bribe an administrator or two.
The alternative is to look up the relevant information in Active Directory, which is apparently what Outlook does. See this MSDN thread for a more elaborate explanation, but this is the gist:
Outlook has its own directory interfaces it doesn't use EWS to get this information. If your going to use only EWS you need to get your administrator to create a roomlist for you to use.
The last alternative is to use PowerShell to get the mailbox type. This is what I just used to get the rooms in my Exchange Online server:
PS H:\> Get-Mailbox | Where {$_.ResourceType -eq "Room"}
The output:
Name Alias ServerName ProhibitSendQuota
---- ----- ---------- -----------------
Frank's room franksroom db3pr03mb058 49.5 GB (53,150,220,288 bytes)
Another example that generates the same output:
PS H:\> Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")'
With this output I can then get the mailbox with either of these:
exchange.ResolveName("Frank's room");
exchange.ResolveName("[email protected]");
A few relevant links for that:
Upvotes: 6