I am trying to send an email from node+express application. I am using sendgrid for sending the emails. Data for the email text is taken from the jade, supported by node. Although the email is getting delievered to the respective email, but the template is send as plain HTML(no css is getting applied).
Following is my API for sending the email:
router.post('/registered/email/send', function (req, res, next) {
var template = process.cwd() + '/views/email.jade';
fs.readFile(template, 'utf8', function (err, file) {
if (err) {
return res.send('ERROR!');
} else {
var compiledTmpl = _jade.compile(file, { filename: template });
var context = { title: 'Title text', name: req.body.name };
var html = compiledTmpl(context);
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations: [
{
to: [
{
email: req.body.email,
},
],
subject: 'Subject',
},
],
from: {
email: 'test@gmail.com',
},
content: [
{
type: 'text/html',
value: html,
},
],
},
});
sg.API(request, function (error, response) {
if (error) {
console.log('Error response received');
} else {
res.send('success');
}
});
}
});
});
Following is my email.jade:
extends layout
block content
div.body-container
h1.title Footworks School of Dance
p Hi #{name}, title is <strong>#{title}</strong>.
I have checked my layout.jade, where i have added respective css file as well.
Is there anything else i am missing or doing incorrect ?