I'm using Microsoft EWS notification streaming to monitor a mailbox for new messages. It is doing exactly what I need it to do except i'm having trouble pulling out the new email addresses from the message for To and From. I'm using Microsoft's sample application they gave me here http://www.microsoft.com/en-us/download/details.aspx?id=27154 but can't figure it out. Any help is appreciated.
privatestaticvoid OnNotificationEvent(object sender, NotificationEventArgs args)
{
// Extract the item ids for all NewMail Events in the list.
var newMails =from ein args.Events.OfType<ItemEvent>()
where e.EventType ==EventType.NewMail
select e.ItemId;
// Note: For the sake of simplicity, error handling is ommited here.
// Just assume everything went fine
var response = _ExchangeService.BindToItems(newMails,
newPropertySet(BasePropertySet.IdOnly,ItemSchema.DateTimeReceived,
ItemSchema.UniqueBody,ItemSchema.Subject,
ItemSchema.DisplayTo,ItemSchema.InternetMessageHeaders,
ItemSchema.Body));
var items = response.Select(itemResponse => itemResponse.Item);
//ExtendedPropertyDefinition transportMsgHdr = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String);
foreach (var item in items)
{
Console.Out.WriteLine("A new mail has been created. Received on {0}", item.DateTimeReceived);
Console.Out.WriteLine("Subject: {0}", item.Subject);
Console.Out.WriteLine("To: {0}", item.DisplayTo);
Console.Out.WriteLine("Body: {0}", item.Body);
Console.Out.WriteLine("ID: {0}", item.Id);
Console.Out.WriteLine("Headers: {0}", item.InternetMessageHeaders);
}
}
Michael Duhon