如何使用Microsoft Graph v1.0在从Outlook获取经过过滤的电子邮件时应用过滤器

时间:2019-05-16 08:04:00

标签: outlook microsoft-graph

我正在尝试获取用户过滤的电子邮件列表。他们必须能够在多个选项之间进行选择,包括“发件人”和/或“收件人”电子邮件。当我同时使用两个emailAddress过滤器提交查询时,出现以下错误:

RequestBroker--ParseUri:属性“ emailAddress”的属性访问的父值不是单个值。属性的访问只能被应用到一个单一的值。

我的代码(顺便说一句)如下:

  try {    
    var fecha1 = new Date(req.body.fecha1);        
    var fecha2 = new Date(req.body.fecha2);        
    var fecha1 = fecha1.getFullYear() + "-" + fecha1.getMonth() + "-" + fecha1.getDate();
    var fecha2 = fecha2.getFullYear() + "-" + fecha2.getMonth() + "-" + fecha2.getDate();                

    var tipoFecha = (req.body.i_o == 1) ? "receivedDateTime" : "sentDateTime";

    var filtro = "startswith(subject, \'" + req.body.subject + "\') and " +
    "startswith(from/emailAddress/name,\'" + req.body.from + "\') or " + 
    "startswith(toRecipients/emailAddress/name,\'" + req.body.to + "\') and " + 
    tipoFecha + " ge " + fecha1 + " and " + 
    tipoFecha + " lt " + fecha2;

    let result = await client
    .api("/me/mailFolders/inbox/messages?filter=" + filtro)
    .select('id,subject,from,toRecipients,ccRecipients,bccRecipients,body,sentDateTime,receivedDateTime')
    .get();

    var emails = {
      estado: 1,
      descripcion: "ok",
      correos: result.value
    };

    res.json(emails);

 }

我的问题是,还有其他方法可以同时过滤两个电子邮件地址吗?

0 个答案:

没有答案