Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从EWS中收到的电子邮件中获取UniqueBody?_C#_Exchangewebservices - Fatal编程技术网

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;