首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用node-ews软件包阅读带正文和附件的未读邮件

如何使用node-ews软件包阅读带正文和附件的未读邮件
EN

Stack Overflow用户
提问于 2020-07-28 16:09:28
回答 1查看 632关注 0票数 0

我可以使用这个node-ews包发送电子邮件,但我找不到合适的示例来读取收件箱文件夹中的电子邮件,并从电子邮件中获取正文和附件。

我已经看过微软的文档,例如https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-work-with-exchange-mailbox-items-by-using-ews-in-exchange#get-an-item-by-using-the-ews-managed-api,但示例是用C#、C++或VB提供的。

但我想用Nodejs来做这件事。

EN

回答 1

Stack Overflow用户

发布于 2020-09-07 13:31:39

您可以使用以下代码通过FindItem函数从收件箱中获取电子邮件,然后使用GetItem函数读取每封电子邮件

代码语言:javascript
复制
 // Read emails from Inbox
    var ewsFunction = 'FindItem';
    var ewsArgs = {
        'attributes': {
            'Traversal': 'Shallow'
        },
        'ItemShape': {
            't:BaseShape': 'IdOnly',
            't:AdditionalProperties': {
            't:FieldURI': {
                'attributes': {
                'FieldURI': 'item:Subject'
                }
            }
          }
        },
        'ParentFolderIds' : {
            'DistinguishedFolderId': {
            'attributes': {
                'Id': 'inbox'
            }
          }
        }
    };
    // Itreate over all the emails and store Id and ChangeKey.
    ews.run(ewsFunction, ewsArgs, ewsSoapHeader)
    .then(result => {
        // Iterate over the result and extract Id and ChangeKey of the messages and pass those to GetItem function to read messages
    })
    
    // For reading individual messages returned by FindItem (using Id and ChangeKey)
    var ewsFunction = 'GetItem';
      var ewsArgs = {
        'ItemShape': {
          'BaseShape': 'Default',
          't:AdditionalProperties': {
            't:FieldURI': {
                'attributes': {
                'FieldURI': 'item:Attachments'
                }
            }
            }
          },
        'ItemIds' : {
          'ItemId': {
            'attributes': {
              'Id': Id,
              'ChangeKey' : ChangeKey
            }
          }
        }
      };
      await ews.run(ewsFunction, ewsArgs, ewsSoapHeader)
      .then(result => {
          // Iterate over the result and extract meesage
      })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63129683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档