使用readFileSync编码为utf8在jade电子邮件模板中呈现HTML

bob*_*obb 3 javascript node.js express pug

我正在尝试发送一个玉石电子邮件模板,但它目前在实际的电子邮件中将所有内容呈现为字符串而不是HTML.我尝试寻找其他编码类型,fs.readFileSync但不确定这是否应该改变.

在这里调用模板:

var emailTemplate = jade.compile(fs.readFileSync('./views/email/new_user.jade', 'utf8'));
    var html = emailTemplate({
      confirmCode: 233,
      name: params.name,
      siteName: config.siteName
      siteLogo: config.siteLogo
    });
Run Code Online (Sandbox Code Playgroud)

模板:

div(style='width: 300px; margin: 0 auto')
  div(style='text-align: center')
    img(src='#{siteLogo}')
  | Hi #{name},
  p
    | Welcome to #{siteName}! You can now vote on submissions and leave comments.
    | In order for your submissions to be public, please confirm your account by
    | clicking the confirmation link below
  div(style='background-color: #fafafa; border: 1px solid #ddd; border-right: none; border-left: none; display: block; font-weight: bold; line-height: 35px; height: 35px; text-align: center; width:    100%;')
    a(href='http://localhost/users/confirm/') Confirm your account
Run Code Online (Sandbox Code Playgroud)

输出(在我的电子邮件中):

<div style="width: 300px; margin: 0 auto"><div style="text-align: center"><img src="http://localhost/site_logo.png"/></div>Hi USER,<p>Welcome to SITENAME! You can now vote on submissions and leave comments. In order for your submissions to be public, please confirm your account by clicking the confirmation link below</p><div style="background-color: #fafafa; border: 1px solid #ddd; border-right: none; border-left: none; display: block; font-weight: bold; line-height: 35px; height: 35px; text-align: center; width: 100%;"><a href="http://localhost/users/confirm/">Confirm your account</a></div></div>
Run Code Online (Sandbox Code Playgroud)

gus*_*nke 6

我认为你有这个问题,因为Content-Type你的电子邮件不是text/html.试着这样做.