RTKHOT
asked on
How to get ToRecipients in Exchange Web Service
Experts,
I am working on Exchange Web Service API to read mails from a users inbox. I want to do the following
When i am trying to fetch the intended recipients, ToRecipients property of the EmailMessage class is always empty. Any idea why this is happening? I am attaching my code along with this question.
Working on Exchange Server 2010, Visual Studio 2008
It's an urgent requirement. Ur help is much needed.
Thank you
I am working on Exchange Web Service API to read mails from a users inbox. I want to do the following
Get the list of mails from a users inbox - Done.
Resend these mails again to their intended recipients - PROBLEM
When i am trying to fetch the intended recipients, ToRecipients property of the EmailMessage class is always empty. Any idea why this is happening? I am attaching my code along with this question.
Working on Exchange Server 2010, Visual Studio 2008
It's an urgent requirement. Ur help is much needed.
Thank you
Imports System
Imports System.Configuration
Imports System.Net
Imports Microsoft.Exchange.WebServices.Autodiscover
Imports Microsoft.Exchange.WebServices.Data
Public Class Form2
#Region "Private members"
Private _objService As ExchangeService
#End Region
#Region "Form/Control events"
Private Sub FormLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitializeService()
ProcessMailQueue()
End Sub
#End Region
#Region "User defined methods"
Private Sub InitializeService() ''Initializes Exchange service
Try
_objService = New ExchangeService(ExchangeVersion.Exchange2010)
_objService.Credentials = New WebCredentials("xxxx@xxxx.com", "xxxxxx")
_objService.AutodiscoverUrl("xxxx@xxxx.com")
Catch ex As Exception
End Try
End Sub
Private Function GetInboxItems() As FindItemsResults(Of Item)
Dim objFindItemResults As FindItemsResults(Of Item)
Try
objFindItemResults = _objService.FindItems(WellKnownFolderName.Inbox, New ItemView(10))
Catch ex As Exception
End Try
Return objFindItemResults
End Function
Private Sub ProcessMailQueue()
Dim objMails As FindItemsResults(Of Item)
Dim objItem As Item
Try
objMails = GetInboxItems() ''Getting mails from users inbox
For Each objItem In objMails ''Looping thru found items and resend them
ResendMail(objItem)
Next
Catch ex As Exception
End Try
End Sub
Private Sub ResendMail(ByVal Mail As EmailMessage)
Dim objEmail As EmailMessage
Dim objEmailAddress As EmailAddress
objEmail = New EmailMessage(_objService)
For Each objEmailAddress In Mail.ToRecipients ''Mail.ToRecipients list is always empty!
objEmail.ToRecipients.Add(objEmailAddress)
Next
objEmail.Subject = Mail.Subject
objEmail.Body = Mail.Body
objEmail.SendAndSaveCopy()
End Sub
#End Region
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER