1

我正在尝试从 node+express 应用程序发送电子邮件。我正在使用sendgrid发送电子邮件。电子邮件文本的数据取自Jade,由节点支持。虽然电子邮件正在发送到相应的电子邮件,但模板以纯 HTML 格式发送(没有应用 css)。

以下是我发送电子邮件的 API:

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');
    }
  });
 }
});
});

以下是我的 email.jade:

extends layout

block content
 div.body-container
 h1.title Footworks School of Dance
 p Hi #{name}, title is <strong>#{title}</strong>.

我检查了我的 layout.jade,在那里我也添加了相应的 css 文件。

我还有什么遗漏或做错了吗?

4

1 回答 1

1

一些电子邮件服务提供商,如 gmail 或 yahoo 阻止 css 链接,您应该在模板中使用内联样式,使用此链接查看电子邮件客户端支持哪些 css 属性

于 2018-01-19T12:59:07.650 回答