I\'m trying to build a web application using express.js. In my application, I\'m using nodemailer for sending mail. If I just use it to send basic mail it work ok; however, when
I have updated the answer using ES6 and ES8 features, just in case anyone needs it.
Don't forget to use it in an async function.
const fs = require("fs");
const nodemailer = require("nodemailer");
const ejs = require("ejs");
const transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true,
auth: {
user: 'testmail@zoho.com',
pass: '123456'
}
});
const data = await ejs.renderFile(__dirname + "/test.ejs", { name: 'Stranger' });
const mainOptions = {
from: '"Tester" testmail@zoho.com',
to: 'totest@zoho.com',
subject: 'Hello, world!',
html: data
};
transporter.sendMail(mainOptions, (err, info) => {
if (err) {
console.log(err);
} else {
console.log('Message sent: ' + info.response);
}
});