Reputation: 149
I want to send an email with html template. In that template I want to add few dynamic data while sending the email.
Like my html page having one link, but I want to add one id inside the link.
Is it possible to add dynamic data in html data while sending email, if it is, please help me to find out the solution.
Upvotes: 2
Views: 4169
Reputation: 1153
yes, just build the string for the html before sending the email.
var name = "John";
var link = "http://www.example.com/id="+1;
mailOptions = {
...
html: '<a href="'+ link +'">'+name+'</a>'
};
Upvotes: 5
Reputation: 2567
You have to read the documentation on the nodemailer website. https://nodemailer.com
But here is a straightforward example:
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
host: 'smtp.example.com',
port: 587,
secure: false, // upgrade later with STARTTLS
auth: {
user: 'username',
pass: 'password'
}
// send mail
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Message title',
html: '<p>HTML version of the message</p>'
}
Upvotes: -4