首页 文章

Outlook API获取邮件未返回附件集合

提问于
浏览
1

我使用Outlook Mail REST API来获取用户电子邮件集合的JSON对象,并在自定义Web界面中显示数据 . 我需要显示电子邮件列表,列表中的每封电子邮件都需要指明该特定电子邮件的附件数量 .

我正在使用来自 Outlook Mail REST API reference #Getmessages 路径的Get Messages来获取我需要的所有数据 . 但是当我在 $select 中指定我想要 Attachments 时,我从未收到每封电子邮件的附件集合;它只是缺失了 .

我可以为每封电子邮件获取附件集合,并为每封电子邮件提供单独的请求,如果我需要一次100封电子邮件的附件计数,这将是丑陋的 .

根据这个:(https://msdn.microsoft.com/office/office365/api/complex-types-for-mail-contacts-calendar#RESTAPIResourcesMessage)我应该能够在我获取消息时指定是否需要附件集合,但它不起作用 . 我正在使用Node.js来获取电子邮件集合:

var requestUrl = "https://outlook.office.com/api/v2.0/me/messages";

var queryParams = {
    '$select': 'Subject, ReceivedDateTime, From, ToRecipients, HasAttachments, Attachments, WebLink, CcRecipients, Body',
    '$orderby': 'ReceivedDateTime desc',
    '$filter' : dateString,
    '$top': 300
};

...

Returned Email Object in Collection

如果我包含它或排除它, $select 中的每个选项都能正常工作,但始终缺少 Attachments . 有没有人有办法解决吗?

1 回答

  • 1

    Attachments 是一个导航属性,因此您需要通过附加 $expand 参数来请求它获得"expanded":

    https://outlook.office.com/api/v2.0/me/mailfolders/inbox/messages?
      $select=Subject,Attachments&$filter=HasAttachments eq true&$expand=Attachments
    

相关问题