I have the following code in place, and it works:
private void OnEvent(object sender, NotificationEventArgs args)
{
StreamingSubscription sub = args.Subscription;
foreach (NotificationEvent notification in args.Events)
{
switch (notification.EventType)
{
case EventType.NewMail:
if (notification is ItemEvent)
{
ItemEvent item = (ItemEvent)notification;
EmailMessage message = EmailMessage.Bind(service, item.ItemId);
string fAddress = message.From.Address;
string subject = message.Subject;
string body = message.Body.Text;
string tAddress = message.ToRecipients[0].Address;
//and so on...
}
break;
}
}
}
However, if I try to set “body” equal to UniqueBody like this…
string body = message.UniqueBody.Text;
That errors out saying, “You must load or assign this property before you can read its value.” I was hoping UniqueBody would work out-of-the-box, meaning I wouldn’t have to parse a new email to grab the new details I care about. I’m assuming there is something easy I’m missing. Any ideas?
When you bind the
ItemIdyou wish to receive you need to be explicit in which properties you want.For example,
The
PropertySetclass has an overload that includesparams[]so you’re free to include/exclude a number of additional properties. Simply look through theItemSchemaenum and select the ones you want.