使用 EWS 托管 api Nodejs 实现从自定义文件夹中读取 MS-Exchange 电子邮件

有没有办法使用 EWS 托管 api(NodeJs 实现)从 MS-Exchange 中的自定义文件夹中读取电子邮件?我可以从收件箱中读取,但我有自定义文件夹名称,电子邮件将移至该名称,我希望在这些文件夹中读取代码。


我试过什么。


const EWS = require('node-ews');

const ewsConfig = {

    username: '<Email>',

    password: '<Password>',

    host: '<Exchange URL>'

};

const ews = new EWS(ewsConfig);

const ewsFunction = 'FindItem';

var ewsArgs = {

    'attributes': {

        'Traversal': 'Shallow'

    },

    'ItemShape': {

        't:BaseShape': 'IdOnly',

        't:AdditionalProperties': {

            't:FieldURI': {

                'attributes': {

                    'FieldURI': 'item:Subject'

                }

            }

        }

    },

    'ParentFolderIds': {

        'DistinguishedFolderId': {

            'attributes': {

                'Id': '<Some Custom Folder>'

            }

        }

    }

};


(async function () {

   

    try {

        let result = await ews.run(ewsFunction, ewsArgs);

        console.log(result);

    } catch (err) {

        console.log(err.message);

    }

})();

    

错误:


a:ErrorInvalidRequest: The request is invalid.: {"ResponseCode":"ErrorInvalidRequest","Message":"The request is invalid."}


莫回无
浏览 171回答 2
2回答

qq_遁去的一_1

DistinguishedFolderId 不适用于非默认文件夹,因此我建议您尝试&nbsp; &nbsp; 'ParentFolderIds': {&nbsp; &nbsp; &nbsp; &nbsp; 'FolderId': {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'attributes': {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Id': '<Some Custom Folder>'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }

潇湘沐

我让它工作的方法是首先找到FolderId使用FindFolder调用的方法:const ewsArgs = {&nbsp; FolderShape: {&nbsp; &nbsp; BaseShape: 'AllProperties',&nbsp; },&nbsp; ParentFolderIds: {&nbsp; &nbsp; DistinguishedFolderId: {&nbsp; &nbsp; &nbsp; attributes: {&nbsp; &nbsp; &nbsp; &nbsp; Id: 'inbox',&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; Mailbox: {&nbsp; &nbsp; &nbsp; &nbsp; EmailAddress: 'emailaddress@company.com',&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; },&nbsp; },};const { ResponseMessages } = await ews.run('FindFolder', ewsArgs, ews.ewsSoapHeader);const found = ResponseMessages.FindFolderResponseMessage.RootFolder.Folders.Folder&nbsp; .find(f => f.DisplayName.match(new RegExp(folderName.toLowerCase(), 'ig')));之后,您可以使用它来查找文件夹中包含以下呼叫的所有电子邮件FindItem:const ewsArgs = {&nbsp; attributes: {&nbsp; &nbsp; Traversal: 'Shallow',&nbsp; },&nbsp; ItemShape: {&nbsp; &nbsp; BaseShape: 'IdOnly',&nbsp; &nbsp; // BaseShape: 'AllProperties',&nbsp; },&nbsp; ParentFolderIds: {&nbsp; &nbsp; FolderId: found.FolderId,&nbsp; },};const { ResponseMessages } = await ews.run('FindItem', ewsArgs, ews.ewsSoapHeader);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript