简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM