How to retrieve email address from the “From” and “To” field of mail item using EWS Managed API?
In case we are calling FindItem for EWS Managed API then, it will provide much of the information that a client application needs. It basically returns a summary of an item. FindItem returns only the first 512 bytes of any streamable property. For Unicode, it returns the first 255 characters by using a null-terminated Unicode string.
FindItem does not return a message body, attachments, or recipient lists.
Use GetItemType to get the details of specific items. GetItem returns more properties than FindItem. If more information is required, a client application must perform a FindItem call and then use the item identifiers in a GetItem call to get the properties that are not available in the FindItem call.
IMP NOTE: Although the Sender property is returned in both FindItem and GetItem calls, only the DisplayName is returned in the FindItem call. DisplayName, EmailAddress, and RoutingType (EmailAddress) are returned by the GetItem call.
So, here’s sample code snippet to get DisplayName, EmailAddress in C#
NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.
//We are making GetItem call using ManagedAPI here after getting the ItemId from FindItem call
EmailMessage message = EmailMessage.Bind(service, myItem.Id ,
new PropertySet (BasePropertySet.FirstClassProperties , ItemSchema.Attachments));
MessageBox.Show( message.From.Name + " " + message.From.Address );
MessageBox.Show( message.ToRecipients.Count.ToString());
foreach( EmailAddress eAdd in message.ToRecipients )
{
MessageBox.Show(eAdd.Name + " " +eAdd.Address);
}
EWS Managed API Rocks!!!
Comments
- Anonymous
February 24, 2013
You Rock!!!Thanks a lot for your articleDon't stop sharing your knowledgeFew lines of code, a lot of help, thanks again