You can do it. Read the HTML file with fs and store in a variable. Now pass this variable email data
Try entering a code.
var fs = require('fs'); var mailGun = require("mailgun-js")({ apiKey: "API-KEY", domain:"DOMAIN-NAME" }); var emailBody = fs.readFileSync('your html file path').toString(); var emailData = { from: "fromEmail", to: "toEmail", subject: "subject", html: emailBody } mailGun.messages().send(emailData, function (error, body) { if(!error){ console.log("sendEmail : email Sent to : "+email); }else{ console.log("sendEmail : Can not send email to : "+email+" : Error : "+error); } });
This solution works for me.
source share