Solved
Exchange Web Services - From Fields Not Populated??
Posted on 2014-02-10
Hi,
I recently downloaded the Exchange Web Services SDK and have used it to create a small application who's aim is to extract data regarding email usage. One of the fields I am interested in is the sender and in particular I need to get the Sender's email address. Most of the other fields seem to contain what I want but anything that involves email addresses seems to be set to nothing yet the name field holds the sender's name. Here is the bare bones of what I am doing:
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Net
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports Microsoft.Exchange.WebServices.Data
Dim Str As String = ""
Dim l As Integer = 0
Dim parentFolderName As WellKnownFolderName
Dim view As New ItemView(1000)
Dim returnValue As FindItemsResults(Of Item)
Dim x As Integer = 0
Dim n As Integer = 0
Dim service As ExchangeService = Nothing
service = New ExchangeService(ExchangeVersion.Exchange2010)
ServicePointManager.ServerCertificateValidationCallback = AddressOf CertificateValidationCallBack
service.Credentials = New WebCredentials(A.UserName, A.Password, A.Domain)
service.AutodiscoverUrl(A.EmailAddress)
parentFolderName = WellKnownFolderName.Inbox
If returnValue.Items.Count > 0 Then
For j = 0 To returnValue.Items.Count - 1
Str = DirectCast(returnValue.Items(j), Microsoft.Exchange.WebServices.Data.EmailMessage).From.Address
If Str = "" Then
lstResults.Items(l).SubItems.Add("-")
Else
lstResults.Items(l).SubItems.Add(Str)
End If
l += 1
Next
End if
When I interrogate the " DirectCast(returnValue.Items(j), Microsoft.Exchange.WebServices.Data.EmailMessage).From.Address" code the address is always nothing, if I look at:
DirectCast(returnValue.Items(j), Microsoft.Exchange.WebServices.Data.EmailMessage).From.name
That has the name of the sender which is not what I want, can anyone explain what I need to do to get the email address of the sender. I am also getting the same with the CC and BCC fields they are always empty even when there are actual CC and BCCs in the inbox email message I am interrogating.
Siv