【问题标题】:Does the Microsoft Graph .NET client library support filtering messages by body and creation date?Microsoft Graph .NET 客户端库是否支持按正文和创建日期过滤消息?
【发布时间】:2021-07-28 20:57:32
【问题描述】:

我在我的项目中使用这个库 (Microsoft Graph .NET client library) 从我的邮箱中检索电子邮件。但是,当我尝试按 createdDateTime 或正文过滤邮箱中的邮件时,我收到“错误请求”错误。以下是我的要求:

    private static IMailFolderMessagesCollectionPage GetMessages(string subject, int count)
    {
        return new graphServiceClient.Me.MailFolders.Inbox.Messages.Request().Filter($"subject eq '{subject}' and createdDateTime gt '{DateTime.Now.AddMinutes(-10)}'").Top(count).GetAsync().Result;
    }

    private static IMailFolderMessagesCollectionPage GetMessages(string subject, string bodyPart, int count)
    {
        return new graphServiceClient.Me.MailFolders.Inbox.Messages.Request().Filter($"subject eq '{subject}' and body contains '{bodyPart}'").Top(count).GetAsync().Result;
    }

我使用的 Microsoft Graph API 和库本身是否支持按 createdDateTime 和正文过滤电子邮件(消息)?如果是这样,有谁知道问题出在哪里?

UPD

原来我有错误的请求来按正文过滤电子邮件。下面是正确的查询,但我还找不到该查询的任何字母。也许有人会觉得它有用。

    private static IMailFolderMessagesCollectionPage GetMessages(string subject, string bodyPart, int count)
    {
        return new graphServiceClient.Me.MailFolders.Inbox.Messages.Request().Filter($"subject eq '{subject}' and contains(body/content, '{bodyPart}')").Top(count).GetAsync().Result;
    }

【问题讨论】:

    标签: c# microsoft-graph-api microsoft-graph-sdks


    【解决方案1】:

    要按 createdDateTime 过滤,您应该删除 '' 并使用 ISO 8601 格式。例如:2021-07-29T14:32:12Z

    在你的情况下,你可以使用ToString("s"),请找到如下代码:

    return new graphServiceClient.Me.MailFolders.Inbox.Messages.Request().Filter($"subject eq '{subject}' and createdDateTime gt {DateTime.UtcNow.AddMinutes(-10).ToString("s")}Z").Top(count).GetAsync().Result;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      相关资源
      最近更新 更多