I am trying to get the real email address of the sender of an email using Exchange web services, however the mailitem.Sender.Address
contains something like -
/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (...........)/CN=RECIPIENTS/CN=...........-.....
How can I get to the real email address of the sender of this email?
My code:
Dim sf As SearchFilter = New SearchFilter.SearchFilterCollection(LogicalOperator.And, New SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, False))
Dim findResults As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, sf, New ItemView(128))
Dim items As ServiceResponseCollection(Of GetItemResponse) = service.BindToItems(findResults.Select(Function(item) item.Id), New PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients))
For Each itItem As Microsoft.Exchange.WebServices.Data.Item In findResults.Items
If TypeOf itItem Is EmailMessage Then
Dim mailItem As EmailMessage = DirectCast(itItem, EmailMessage)
And then I want to refer to mailItem.Sender.Address
, which contains the above mentioned string instead of abc@whatever.com
Some example code, preferably in VB.NET
, would be appreciated as I have a hard time figuring out how these Exchange web services work.