尝试使用 Exchange Web 服务获取电子邮件时出现 ServiceObjectPropertyException?

use*_*415 4 c# exchangewebservices

我正在尝试获取未读电子邮件,然后将其标记为已读。

当我运行代码时出现此异常:

ServiceObjectPropertyException 未处理:

Microsoft.Exchange.WebServices.dll 中发生类型为“Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException”的未处理异常

当我尝试将 Exchange 邮件对象映射到业务模型对象时发生此错误。

这是映射方法:

class MailMapper
{
     public static PhishingMail Map(EmailMessage OutlookMail)
     {
          //Map Exchange email object op Business model email object
          PhishingMail readMail = new PhishingMail();
          readMail.Subject = OutlookMail.Subject;
          return readMail;
      }
}
Run Code Online (Sandbox Code Playgroud)

这是应该将电子邮件标记为已读的代码。

public List<PhishingMail> GetEmails() 
{
    phishingMailList = new List<PhishingMail>();

    FolderId InboxId = new FolderId(WellKnownFolderName.Inbox, "A*******m@i*****nl");

    FindItemsResults<Item> findResults = service.FindItems(InboxId, new ItemView(100));

    foreach (Item phishingmail in findResults.Items)
    {
        ((EmailMessage)phishingmail).Load(new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.IsRead)); 

        if (!((EmailMessage)phishingmail).IsRead) 
        {
            ((EmailMessage)phishingmail).IsRead = true;
            ((EmailMessage)phishingmail)
                .Update(ConflictResolutionMode.AutoResolve);
        }

        PhishingMail mail = MailMapper.Map((EmailMessage)phishingmail);

        phishingMailList.Add(new PhishingMail());

        ///   Console.WriteLine(mail.Subject);
    }
    return phishingMailList;
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?地图方法有什么问题?

Hen*_*yer 5

当您加载项目时,您可以指定要加载的属性。

item.Load(new PropertySet(PropertySet.FirstClassProperties)); 
Run Code Online (Sandbox Code Playgroud)

如果加载后需要更多属性,可以执行以下操作:

Service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);
Run Code Online (Sandbox Code Playgroud)