Monday, August 13, 2012

Using Custom MailTips to provide extra information in EWS

The directory functionality in Exchange Web Services can be a little limited and so within Exchange 2010 without using LDAP to access Active Directory directly there is no direct way to access custom Resource properties on Meeting Rooms or where you want to access Custom Attributes. However using Custom MailTips is one way of working around this issue (although it means duplicating the information).

For example to Create a Custom Mail Tip for a mailbox you use

set-mailbox meetingRoom2 -MailTip "Expresso Machine"

Then in EWS you can use this to retrieve the MailTip

  1. GetMailTipsType gmType = new GetMailTipsType();  
  2. gmType.MailTipsRequested = new MailTipTypes();  
  3. gmType.MailTipsRequested = MailTipTypes.CustomMailTip;  
  4. gmType.Recipients = new EmailAddressType[1];  
  5. EmailAddressType rcip1 = new EmailAddressType();  
  6. rcip1.EmailAddress = "MeetingRoom2@domain.com";  
  7. gmType.Recipients[0] = rcip1;  
  8. EmailAddressType sendAs = new EmailAddressType();  
  9. sendAs.EmailAddress = "MeetingRoom2@domain.com";  
  10. gmType.SendingAs = sendAs;  
  11.   
  12. GetMailTipsResponseMessageType gmResponse = esb.GetMailTips(gmType);  
  13. if (gmResponse.ResponseClass == ResponseClassType.Success)  
  14. {  
  15.     foreach (MailTipsResponseMessageType mtResp in gmResponse.ResponseMessages)  
  16.     {  
  17.         Console.WriteLine(mtResp.MailTips.RecipientAddress.EmailAddress);  
  18.         Console.WriteLine(mtResp.MailTips.CustomMailTip);  
  19.     }  
  20. }  


No comments: