node-ews icon indicating copy to clipboard operation
node-ews copied to clipboard

Attachment

Open sotnikoff opened this issue 9 years ago • 9 comments

Is there any way to attach files to sending mails?

sotnikoff avatar Jan 18 '17 14:01 sotnikoff

Unfortunately, I don't have an example JSON request that does exactly this... However, if you start with the example in the README here which references the Microsoft article here, and drill into the Message property which has an Attachments property, you should be able to cobble the JSON request needed.

Create Email: https://msdn.microsoft.com/en-us/library/office/aa566468

Message: https://msdn.microsoft.com/en-us/library/office/aa494306

Attachment: https://msdn.microsoft.com/en-us/library/office/aa564869

nmarus avatar Jan 18 '17 20:01 nmarus

Did you find a way to solve this? @sotnikoff

vhellem avatar Jul 05 '17 07:07 vhellem

Using the links provided by @nmarus is sufficient to create the arguments. But what we also needed to do is include the following variable as the headers argument to ews.run: const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, }; Hopefully this will save someone else a couple of hours of debugging nonsensical EWS errors in the future :fox_face:

roligheten avatar Jul 06 '17 17:07 roligheten

I just got a working example together, thanks to Catuna's ewsHeaders help above and and wanted to share!

let ews = new EWS(ewsConfig);

// define ews api function 
let ewsFunction = 'CreateItem';

// define ews api function args 
let ewsArgs = {
	attributes: {
		MessageDisposition: 'SendAndSaveCopy'
	},
	SavedItemFolderId: {
		DistinguishedFolderId: {
			attributes: {
				Id: 'sentitems'
			}
		}
	},
	Items: {
		Message: {
			ItemClass: 'IPM.Note',
			Subject: subject,
			Body: {
				attributes: {
					BodyType: 'HTML'
				},
				$value: body
			},
			ToRecipients: {
				Mailbox: RecipientsObject.to
			},
			CcRecipients: {
				Mailbox: RecipientsObject.cc
			},
			BccRecipients: {
				Mailbox: RecipientsObject.bcc
			},
			IsRead: 'false',
			Attachments: {
				FileAttachment: [
					{
						Name: 'firstAttachment.txt',
						IsInline: false,
						IsContactPhoto: false,
						ContentType: 'text/plain',
						Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
					},
					{
						Name: 'secondAttachment.txt',
						IsInline: false,
						IsContactPhoto: false,
						ContentType: 'text/plain',
						Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
					}
				]
			}
		}
	}
};

const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, };

ews.run(ewsFunction, ewsArgs, ewsHeaders)
	.then(() => {
		return resolve();
	})
	.catch(error => {
		console.error('Send Email Service v1 Error: ' +  error.message);
		return reject('Send Email Service v1 Error: ' + error.message);
	});

yolixtly avatar Oct 25 '17 16:10 yolixtly

Thank god, I was about to pull my hair out 😄 ! @Catuna

elertan avatar Aug 20 '18 12:08 elertan

I just got a working example together, thanks to Catuna's ewsHeaders help above and and wanted to share!

let ews = new EWS(ewsConfig);

// define ews api function 
let ewsFunction = 'CreateItem';

// define ews api function args 
let ewsArgs = {
	attributes: {
		MessageDisposition: 'SendAndSaveCopy'
	},
	SavedItemFolderId: {
		DistinguishedFolderId: {
			attributes: {
				Id: 'sentitems'
			}
		}
	},
	Items: {
		Message: {
			ItemClass: 'IPM.Note',
			Subject: subject,
			Body: {
				attributes: {
					BodyType: 'HTML'
				},
				$value: body
			},
			ToRecipients: {
				Mailbox: RecipientsObject.to
			},
			CcRecipients: {
				Mailbox: RecipientsObject.cc
			},
			BccRecipients: {
				Mailbox: RecipientsObject.bcc
			},
			IsRead: 'false',
			Attachments: {
				FileAttachment: [
					{
						Name: 'firstAttachment.txt',
						IsInline: false,
						IsContactPhoto: false,
						ContentType: 'text/plain',
						Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
					},
					{
						Name: 'secondAttachment.txt',
						IsInline: false,
						IsContactPhoto: false,
						ContentType: 'text/plain',
						Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
					}
				]
			}
		}
	}
};

const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, };

ews.run(ewsFunction, ewsArgs, ewsHeaders)
	.then(() => {
		return resolve();
	})
	.catch(error => {
		console.error('Send Email Service v1 Error: ' +  error.message);
		return reject('Send Email Service v1 Error: ' + error.message);
	});

how i can use FileAttachment with a file location, i mean i have 2 files .xlsx into my fileserver and i want use the file route of these files and attached into my mail. you was try that?

dandreaf avatar Jul 09 '20 23:07 dandreaf

I just got a working example together, thanks to Catuna's ewsHeaders help above and and wanted to share!

let ews = new EWS(ewsConfig);

// define ews api function 
let ewsFunction = 'CreateItem';

// define ews api function args 
let ewsArgs = {
	attributes: {
		MessageDisposition: 'SendAndSaveCopy'
	},
	SavedItemFolderId: {
		DistinguishedFolderId: {
			attributes: {
				Id: 'sentitems'
			}
		}
	},
	Items: {
		Message: {
			ItemClass: 'IPM.Note',
			Subject: subject,
			Body: {
				attributes: {
					BodyType: 'HTML'
				},
				$value: body
			},
			ToRecipients: {
				Mailbox: RecipientsObject.to
			},
			CcRecipients: {
				Mailbox: RecipientsObject.cc
			},
			BccRecipients: {
				Mailbox: RecipientsObject.bcc
			},
			IsRead: 'false',
			Attachments: {
				FileAttachment: [
					{
						Name: 'firstAttachment.txt',
						IsInline: false,
						IsContactPhoto: false,
						ContentType: 'text/plain',
						Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
					},
					{
						Name: 'secondAttachment.txt',
						IsInline: false,
						IsContactPhoto: false,
						ContentType: 'text/plain',
						Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
					}
				]
			}
		}
	}
};

const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, };

ews.run(ewsFunction, ewsArgs, ewsHeaders)
	.then(() => {
		return resolve();
	})
	.catch(error => {
		console.error('Send Email Service v1 Error: ' +  error.message);
		return reject('Send Email Service v1 Error: ' + error.message);
	});

how i can use FileAttachment with a file location, i mean i have 2 files .xlsx into my fileserver and i want use the file route of these files and attached into my mail. you was try that?

Hi

Have you figured out how to attach files from local storage?

NikitaMigushev avatar Oct 03 '20 13:10 NikitaMigushev

@NikitaMigushev still not, but if you find a solution or how to do it tell me pls

dandreaf avatar Oct 05 '20 15:10 dandreaf

Has anyone solved local storage file attachment?

ShadoKin avatar Feb 23 '21 23:02 ShadoKin