• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1844
  • Last Modified:

How to get ToRecipients in Exchange Web Service


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
    End Sub
#End Region

#Region "User defined methods"
    Private Sub InitializeService() ''Initializes Exchange service
            _objService = New ExchangeService(ExchangeVersion.Exchange2010)
            _objService.Credentials = New WebCredentials("xxxx@xxxx.com", "xxxxxx")
        Catch ex As Exception
        End Try
    End Sub

    Private Function GetInboxItems() As FindItemsResults(Of Item)
        Dim objFindItemResults As FindItemsResults(Of Item)
            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

            objMails = GetInboxItems() ''Getting mails from users inbox

            For Each objItem In objMails ''Looping thru found items and resend them
        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.Subject = Mail.Subject
        objEmail.Body = Mail.Body
    End Sub

#End Region
End Class

Open in new window

1 Solution
did you try using LoadPropertiesForItems method ?

check my code below:

ExchangeService service = oEWS.CallEWSService(); 
                FindItemsResults<Item> findResults = service.FindItems(
                new ItemView(Convert.ToInt16(AppSettings.GetConfigValue("BMAEMailCountPerCall"))));
                if (findResults.Items.Count > 0)
                    service.LoadPropertiesForItems(findResults, PropertySet.FirstClassProperties.BasePropertySet);

Open in new window

RTKHOTAuthor Commented:
Perfect! Resolved one other problem i had as well. thx a lot dude! :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now