I have an HTML sendgrid template and am sending it via Node.js using the npm package 'sendgrid'. Problem is that I always receive the email as text format not HTML even though the template has HTML.
Code:
var email = new sendgrid.Email({
to : '[email protected]',
from : '[email protected]',
subject : 'Saying Hi with HTML Template',
text : 'Body' //This is required
});
email.addFilter('templates', 'enable', 1);
email.addFilter('templates', 'template_id', '12131331.....');
email.addSubstitution('{{TOKEN1}}', 'value');
sendgrid.send(email, function(err, json) {
if (err) { console.error(err); }
console.log(json);
});
Template
<html>
<head><title></title></head>
<body>
<h1>This is a test</h1>
<p>{{TOKEN1}}</p>
<p><a href="http://www.there.com">There</a></p>
<div><%body%></div>
</body>
</html>
Is there a code parameter I'm supposed to set? Or a setting on the template itself to allow HTML?
According to the documentation. You only use the text property if you're sending plain-text. Instead, use the html property to create an HTML message. You can use the built in setHtml
method like the following:
var email = new sendgrid.Email();
email.setHtml('<h1>Some html</h1>');
sendgrid.send(email, function(err, json) { });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With