Save outlook Email attachment using ews-javascript-api npm in node JS

守給你的承諾、 提交于 2021-02-08 12:11:44

问题


I am trying with below solution using ews-javascript-api npm Node JS. but this solution is not working, not able to download attachment (Excel File) to specific path. please provide me proper solution for the same.

var ews = require('ews-javascript-api')
var ExchangeService = ews.ExchangeService;
var service = new ExchangeService(ews.ExchangeVersion.Exchange2010);
service.Credentials = new ews.ExchangeCredentials("userName", "Password");
service.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");

var view = new ews.ItemView(1);

var items = service.FindItems(ews.WellKnownFolderName.Inbox, "hasattachment:true",new ews.ItemView(1)  );
items.then(function (response) {
    "use strict";
    var count = 0;

    for (var item of response.Items) {

        let email = response.Items[0];

          email.Load(new ews.PropertySet(ews.BasePropertySet.IdOnly, [ews.ItemSchema.Attachments,ews.ItemSchema.HasAttachments])).then(() => {           
              let file = email.Attachments.Items[0];
        file.Load().then(() => {
             var fs = require('fs');
              fs.writeFile("test.txt", file.Base64Content.toString(), function (err) {
                  if (err) {
                      return console.log(err);
                  }

                 console.log("The file was saved!");
              }); 

             console.log(file.Base64Content);

          }, (error) => {
            if (error) {
           console.log(error)
            }
       });
     }, function (error) {
           console.log("Email");
           if (error) {
           console.log(error)
         }
       });

         count = count + 1;
     }
     console.log(count);
 }
 );

回答1:


This should be fixed now. New build is published see here

[Disclaimer - I am the author]



来源:https://stackoverflow.com/questions/42508542/save-outlook-email-attachment-using-ews-javascript-api-npm-in-node-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!