In the earlier post we have discussed about Sending HTML template emails using SMTP in NodeJS , now we will learn about how to sending the emails with attachment in Node.js along with with HTML template.
We have already learn and discussed about the node module and how to integrate module to your file. In this we will extend the code.
Earlier mailOptions is like
1 2 3 4 5 6 | var mailOptions = { from: mailset.FromName+'<'+mailset.From+'>', // sender address to: toemail, // list of receivers subject: 'Sending HTML template mails using SMTP in NodeJS', // Subject line html: data // html body }; |
Add the below code to attachment the external file
1 2 3 4 5 6 | attachments: [ { //using URL as an attachment filename: 'anillabs.pdf', // File name in the email filePath: [attachmentUrl] }, ] |
Now mailOptions will changed to
1 2 3 4 5 6 7 8 9 10 11 12 | var mailOptions = { from: mailset.FromName+'<'+mailset.From+'>', // sender address to: toemail, // list of receivers subject: 'Sending HTML template email with attachment in NodeJS', // Subject line html: data, // html body attachments: [ { //using URL as an attachment filename: 'anillabs.pdf', // File name in the email filePath: [attachmentUrl] }, ] }; |
We can multiple attachments to email. Hope it will be useful.
0 Comments
How to create and use the email signatures - Anil Labs · June 26, 2020 at 6:58 am
[…] the previous posts, I have explained that how to send emails using NodeJS, PHP and this is for set the […]
Sending HTML template emails from Oracle APEX - Anil Labs · September 13, 2023 at 4:03 pm
[…] the previous posts we have seen the how to send HTML template emails from PHP, NodeJS, PowerShell and we will see how to send HTML template emails from Oracle APEX, you can use the […]