C# 如何从EWS中收到的电子邮件中获取UniqueBody?
我已经准备好了以下代码,并且可以正常工作:C# 如何从EWS中收到的电子邮件中获取UniqueBody?,c#,exchangewebservices,C#,Exchangewebservices,我已经准备好了以下代码,并且可以正常工作: private void OnEvent(object sender, NotificationEventArgs args) { StreamingSubscription sub = args.Subscription; foreach (NotificationEvent notification in args.Events) { switch (notification.EventType)
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;
}
}
}
然而,如果我试图像这样将“body”设置为UniqueBody
string body = message.UniqueBody.Text;
我希望UniqueBody能够开箱即用,这意味着我不必解析新的电子邮件来获取我关心的新细节。我想我错过了一些简单的东西。有什么想法吗?当您绑定希望接收的
ItemId
时,您需要明确显示所需的属性
比如说,
var propertySet = new PropertySet(ItemSchema.UniqueBody);
var email = EmailMessage.Bind(service, item.ItemId, propertySet);
PropertySet
类有一个重载,其中包含params[]
,因此您可以自由地包含/排除许多其他属性。只需查看ItemSchema
enum并选择所需的属性。当您绑定希望接收的ItemId
时,需要明确显示所需的属性
比如说,
var propertySet = new PropertySet(ItemSchema.UniqueBody);
var email = EmailMessage.Bind(service, item.ItemId, propertySet);
PropertySet
类有一个重载,其中包含params[]
,因此您可以自由地包含/排除许多其他属性。只需查看ItemSchema
enum并选择所需的项。这就是我最后使用的:
PropertySet pSet = new PropertySet(new[]{ ItemSchema.UniqueBody });
pSet.RequestedBodyType = BodyType.Text;
pSet.BasePropertySet = BasePropertySet.FirstClassProperties;
这就是我最终使用的:
PropertySet pSet = new PropertySet(new[]{ ItemSchema.UniqueBody });
pSet.RequestedBodyType = BodyType.Text;
pSet.BasePropertySet = BasePropertySet.FirstClassProperties;