Answer the question
In order to leave comments, you need to log in
How to send Microsoft Exchange email with attachments from local drive using nodejs?
For the second day I have been racking my brains with .xlsx file attachment when sending a Microsoft Exchange email via node.js using the `node-ews` library.
It is Microsoft Exchange that is important, because. I use my corporate mail to automatically send a letter.
In general, it is possible to create a new file, but there is no way to take an already created one and attach its letter ...
Tell me, what am I doing wrong? Or is there a better way to send it?
Here is what is currently available:
//Send file via email
const EWS = require('node-ews');
// exchange server connection info
const ewsConfig = {
username: 'username',
password: 'pass',
host: 'host',
domain: 'domain',
};
// initialize node-ews
const ews = new EWS(ewsConfig);
// define ews api function
const ewsFunction = 'CreateItem';
// define ews api function args
const ewsArgs = {
attributes: {
MessageDisposition: 'SendAndSaveCopy',
},
SavedItemFolderId: {
DistinguishedFolderId: {
attributes: {
Id: 'sentitems',
},
},
},
Items: {
Message: {
ItemClass: 'IPM.Note',
Subject: 'Subject',
Body: 'body',
ToRecipients: {
Mailbox: {
EmailAddress: '[email protected]',
},
},
IsRead: 'false',
Attachments: {
FileAttachment: {
Name: 'filename.xlsx',
IsInline: false,
ContentType: 'application/vnd.ms-excel',
ContentLocation: './filename.xlsx',
Content: '',
},
},
},
},
};
const ewsHeaders = {
't:RequestServerVersion': {
attributes: {
Version: 'Exchange2013_SP1',
},
},
};
// query ews, print resulting JSON to console
ews
.run(ewsFunction, ewsArgs, ewsHeaders)
.then((result) => {
console.log(JSON.stringify(result));
})
.catch((err) => {
console.log(err.stack);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question