blablabla blablabla - 11 months ago 36
Node.js Question

Trouble sending HTML using Node.js and Mailgun

I'm struggling to send HTML in the email. For the testing and to avoid error, I'm using Mailgun's email templates.

I can successfully send Emails, but when I receive them, I see the HTML as plain text. I'm not sure where I made a mistake, since I've been following the doc. Also, I use

mailgun-js
and
mailcomposer
to achieve this goal.

function sendEmailNotif(name) {

var mail = mailcomposer({
from: process.env.MAIL_FROM_ADDRESS,
to: '********@*****.com', // My address, for testing purpose
subject: '

Answer

I think you want this:

function sendEmailNotif(name) {
  fs.readFile(path.join(__dirname, './emailTemplate/alert.html'), function (err, htmlBody) {
    var mail = mailcomposer({
      from: process.env.MAIL_FROM_ADDRESS,
      to: '********@*****.com', // My address, for testing purpose
      subject: '