Exchange 2007: How to include EmailAddress.MailboxType and EmailAddress.Id in a PropertySet?

Hello,

I use the following command to retrieve an email message by its ID:

EmailMessage message = EmailMessage.Bind(service, id);

It is working well however, all of the EmailAddress instances in the EmailMessage.ToRecipients missing important properties such as EmailAddress.MailboxType and EmailAddress.Id

I understand that I must include EmailAddress.MailboxType and EmailAddress.Id in a PropertySet and pass it to Bind method, but I dont know how to do that.

How can I to include EmailAddress.MailboxType and EmailAddress.Id in a PropertySet?

Thank you,


  • Edited by Allan48 Thursday, May 22, 2014 12:01 AM Added the version number
May 21st, 2014 6:46pm

You need to iterate through the recipients and bind to those.  The properties you are after are not on the message, but on the recipient collection

e.g.

foreach (EmailAddress recipient in message.ToRecipients)

{

    recipient.Load(new PropertySet(BasePropertySet.IdOnly, EmailAddress.MailboxType, EmailAddress.Id);

}

Free Windows Admin Tool Kit Click here and download it now
May 22nd, 2014 9:05am

Hi David,

The EmailAddress class does not include the method Load. I get this compiler error:

'Microsoft.Exchange.WebServices.Data.EmailAddress' does not contain a definition for 'Load'

May 22nd, 2014 12:55pm

Good point... Helps if I check first..

MailboxType should be returned already if you request the ToRecipients property.  This sample code shows how to read it from Inbox items:

                Folder inbox = Folder.Bind(ews, WellKnownFolderName.Inbox);
                ItemView view = new ItemView(500, 0, OffsetBasePoint.Beginning);
                view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
                foreach (object item in inbox.FindItems(view))
                {
                    if (item is EmailMessage)
                    {
                        EmailMessage message = EmailMessage.Bind(ews, (item as EmailMessage).Id, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.ToRecipients));
                        foreach (EmailAddress recipient in message.ToRecipients)
                        {
                            Console.WriteLine(string.Format("{0}: {1}", recipient.Address, recipient.MailboxType));
                        }
                    }
                }
MailboxType is a calculated property, it doesn't actually exist as a property.
Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2014 5:01am

Hi David,

I appreciate the information and help you provided.

Unfortunately, the code you mentioned does not work in Exchange 2007. 

Only Exchange 2010 and after return MailBoxType

Thank you,

May 23rd, 2014 10:58am

It is available only in ExpandDL and ResolveName in Exchange 2007, so yes, the above example only works with 2010+.
Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2014 11:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics