我正在尝试获取未读电子邮件,然后将其标记为已读。
运行代码时出现此异常:
ServiceObjectPropertyException是unhandeld:
未处理的类型异常 ' Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException' 发生在Microsoft.Exchange.WebServices.dll
尝试将Exchange邮件对象映射到业务模型对象时发生此错误。
这是Map方法:
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;
}
}
这是将电子邮件标记为已读的代码。
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;
}
我做错了什么? map方法有什么问题?
答案 0 :(得分:2)
加载项目时,需要加载要加载的属性。
item.Load(new PropertySet(PropertySet.FirstClassProperties));
如果加载后需要更多属性,可以执行以下操作:
Service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);