检索复杂属性时发生EWS错误
本文关键字:EWS 错误 复杂 属性 检索 | 更新日期: 2023-09-27 18:27:17
我们有一个Exchange Web Services应用程序,当引用没有主题的电子邮件时,它会引发错误。
我们的自动化流程需要使用电子邮件的主题,因此代码试图引用它。然而,当收件箱中的电子邮件缺少主题时,我想改变行为,而不是抛出错误。
这是我的代码:
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(common.strInboxURL);
//creates a folder object that will point to inbox fold
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
... code removed fro brevity ...
// Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(fid, searchFilterCollection, view);
if (results.Count() > 0)
{
do
{
// set the prioperties we need for the entire result set
view.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
ItemSchema.DisplayTo, EmailMessageSchema.ToRecipients,
EmailMessageSchema.From, EmailMessageSchema.IsRead,
EmailMessageSchema.HasAttachments, ItemSchema.MimeContent,
EmailMessageSchema.Body, EmailMessageSchema.Sender,
ItemSchema.Body) { RequestedBodyType = BodyType.Text };
// load the properties for the entire batch
service.LoadPropertiesForItems(results, view.PropertySet);
因此,在该代码中,错误被抛出到末尾service.LoadPropertiesForItems(results, view.PropertySet);
行的复杂属性get上。
所以,我知道我必须在这里做一些类似Try..Catch
的事情,但是,我需要检查邮件项目的Subject属性是否存在,然后才能引用它来查看它是什么——某种鸡和蛋的问题。
如果没有主题,我需要将电子邮件标记为已读,向团队发送一封警告电子邮件,然后继续处理邮箱中的下一封未读电子邮件。
如有任何关于处理这一问题的最佳方式的建议,我们将不胜感激。
感谢
Subject是未设置还是为空?
您应该能够使用SearchFitler隔离任何这些类型的电子邮件,例如对Subject属性使用Exists Search筛选器,然后将其否定,这样它将返回未设置Subject的任何项目
SearchFilter sfSearchFilteri = new SearchFilter.Exists(ItemSchema.Subject);
SearchFilter Negatesf = new SearchFilter.Not(sfSearchFilteri);
service.FindItems(WellKnownFolderName.Inbox, Negatesf, new ItemView(1000));
然后只需从LoadPropertiesForItems 中排除这些项目
干杯Glen