For specific use cases, you might need to add custom headers to your emails. This can be useful for tracking or integrating with other systems.
Adding Custom Headers:
let mailOptions = {
from: '"Your Name" <[email protected]>',
to: '[email protected]',
subject: 'Custom Header Example',
text: 'This email has custom headers.',
headers: {
'X-Custom-Header': 'CustomHeaderValue',
'X-Another-Header': 'AnotherHeaderValue'
}
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.error('Error sending email:', error);
}
console.log('Email sent:', info.response);
});
Leave a Reply