I have an HTML email template saved in a .html file on my nodejs
express
app.
I am looking to send this as an email template as follows:
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
host: '...',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: '...', // generated ethereal user
pass: '...', // generated ethereal password
},
});
// send mail with defined transport object
const info = await transporter.sendMail({
from: '"Testing " <donotreply@testing.com>', // sender address
to: recipientAddress, // list of receivers
subject, // Subject line
text: striptags(html), // plain text body
html, // html body
});
The problem I'm facing is how do I load the HTML from my template file into the html
JS variable I can use here. I tried the following code but this throws an exception:
const html = require('../path/to/file.html');
<!DOCTYPE html> SyntaxError: Unexpected token '<'
when attempting to run the server.