user3599415
user3599415

Reputation: 283

Retrieve email with exchange web services and put it in a datagrid

I made WPF application with a datagrid. I need to show specific parts of the email in my datagrid. Like date,subject and sender.

I am using exchange web services to get the first 10 mails, which works. But I don't know where to start with getting these specific parts.

This is my Datagrid Load method

    private void DataGrid_Loaded(object sender, RoutedEventArgs e)

    {
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

            //service.Credentials = new NetworkCredential( "{Active Directory ID}", "{Password}", "{Domain Name}" );

            service.AutodiscoverUrl("*****.****@**.nl");

            FindItemsResults<Item> findResults = service.FindItems(
            WellKnownFolderName.Inbox,
            new ItemView(10));

            foreach (Item item in findResults.Items)
                URLGRID.ItemsSource = (item.Subject);
        }
    }
}

What do I need to add to this method to get a datagrid that shows date,subject and sender of the emails. Or am I forgetting something?

Upvotes: 0

Views: 146

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

Probably the easiest way would just be to use LINQ, you may have items of different types (eg calendar invites etc) in the collection because your not filtering it at all but something like this should work okay

URLGRID.ItemsSource = findResults.Where(t => t is EmailMessage).Select(item => new { item.DateTimeReceived, ((EmailMessage)item).Sender.Name, item.Subject });

Cheers Glen

Upvotes: 1

Related Questions