【问题标题】:EWS error when retrieving complex property检索复杂属性时出现 EWS 错误
【发布时间】:2014-10-21 16:14:28
【问题描述】:

我们有一个 Exchange Web 服务应用程序,它在引用没有主题的电子邮件时抛出错误。

我们的自动化流程需要使用电子邮件的主题,因此代码会尝试引用它。但是,当收件箱中的电子邮件缺少主题时,我不想抛出错误,而是想更改行为。

这是我的代码:

//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 的操作,但是,我需要先检查邮件项目的主题属性是否存在,然后才能引用它以查看它是什么——一些一种鸡和蛋的问题。

如果没有主题,我需要将邮件标记为已读,向团队发送警告邮件,然后继续处理邮箱中的下一封未读邮件。

任何有关解决此问题的最佳方法的建议都将不胜感激。

谢谢

【问题讨论】:

    标签: c# email exchangewebservices exchange-server-2010


    【解决方案1】:

    主题是没有设置还是空白?

    您应该能够使用 SearchFitler 隔离任何这些类型的电子邮件,例如,对主题属性使用 Exists Search 过滤器,然后将其取反,这样它将返回未设置主题的任何项目

            SearchFilter sfSearchFilteri = new SearchFilter.Exists(ItemSchema.Subject);
            SearchFilter Negatesf = new SearchFilter.Not(sfSearchFilteri);
    
            service.FindItems(WellKnownFolderName.Inbox, Negatesf, new ItemView(1000));
    

    然后从您的 LoadPropertiesForItems 中排除这些项目

    干杯 格伦

    【讨论】:

      猜你喜欢
      • 2018-08-08
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 2011-10-29
      • 1970-01-01
      • 2014-02-05
      • 2019-03-26
      • 1970-01-01
      相关资源
      最近更新 更多