node.js - 如何使用 node-ews 包阅读带有正文和附件的未读电子邮件
问题描述
我可以使用这个 node-ews 包发送电子邮件,但我找不到合适的示例来从收件箱文件夹中读取电子邮件并从电子邮件中获取正文和附件。
我浏览了 Microsoft 文档,例如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 做到这一点。
解决方案
您可以使用以下代码使用 FindItem 函数从 Inbox 获取电子邮件,然后使用 GetItem 函数阅读每封电子邮件
// 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
})
推荐阅读
- php - 点击时如何在wordpress中调用codeigniter控制器
- bash - 如何使用 bash 脚本在远程主机上执行命令
- apache-kafka - KSQL 中的多个键或外键
- javascript - 如何使用 react-native 实现推送通知
- laravel - Laravel 有两个来自同一张表的外键
- maven-3 - Travis CI 因子模块失败...不存在
- javascript - JavaScript 替换 td 元素中的子字符串
- android - 出于某种原因,ConnectableObservable 在发出 128 个项目后停止
- javascript - 在 VueJS 中使用全局辅助函数
- reactjs - 为什么我的 React 组件处理程序是在渲染时执行的,之后就不能工作了?