Sometimes, we want to pass variable to HTML template in Nodemailer and JavaScript.
In this article, we’ll look at how to pass variable to HTML template in Nodemailer and JavaScript.
How to pass variable to HTML template in Nodemailer and JavaScript?
To pass variable to HTML template in Nodemailer and JavaScript, we put them in the context
object property.
For instance, we write
const mailOptions = {
from: "abc@example.com",
to: "username@example.com",
subject: "Sending email",
template: "yourTemplate",
context: {
username,
whatever,
},
};
to put username
and whatever
into context
.
Then in yourTemplate
, we write
{{ username }}
to render the username
value.
Conclusion
To pass variable to HTML template in Nodemailer and JavaScript, we put them in the context
object property.