1

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 ?

Rohan Kangale
  • 931
  • 4
  • 11
  • 29

1 Answers1

1

Some email service provider like gmail or yahoo block css link, you should use inline style in your template, use this link to see which css properties are supported by email clients

YouneL
  • 8,152
  • 2
  • 28
  • 50