Daniel Flippance Daniel Flippance - 1 year ago 91
HTML Question

Sendgrid Always Sends Text Email

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.


var email = new sendgrid.Email({
to : 'me@here.com',
from : 'you@there.com',
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); }


<h1>This is a test</h1>
<p><a href="http://www.there.com">There</a></p>


Is there a code parameter I'm supposed to set? Or a setting on the template itself to allow HTML?

Answer Source

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) { });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download