To pass variable to html template in Nodemailer, we put them in the context property.
For instance, we write
const mailOptions = {
from: "abc@gmail.com",
to: "username@gmail.com",
subject: "Sending email",
template: "yourTemplate",
context: {
username,
whatever: variable,
},
};
const info = await transporter.sendMail(mailOptions);
to call sendMail with mailOptions to send the email message.
We set the context property to an object with the template variables to interpolate them in the template.