html - 如何在使用 Nodejs 时使用 SendGrid 的电子邮件模板

标签 html node.js heroku html-email sendgrid

我有一个 HTMl 电子邮件模板,我想用它通过 Heroku 向人们发送自动电子邮件。我正在为 Heroku 使用 Sendgrid 插件。

 var html_content = "Thank you for registering to visit Philippine Property Show 2014 organised by"+
 "PropertyGuru.This is the confirmation letter to your registration.Kindly present this letter at the registration counter for your entry to the event."
 +"<br> <br>Thank you once again and see you at the event.<br><br>
<strong>Philippine Property Show</strong><br>
<strong>29 - 30 November 2013</strong><br>
<strong>Orchard Hotel, Level 2, Conference Centre<br>
</strong><br>"+"
<strong><span >With Warm Regards,</span></strong><span ><br>
<br>
</span><strong><span >PropertyGuru Events</span></strong><span ><br>
<br> ";

我有下面的函数,我试图使用上面的变量。

    function send_mail_sendgrid(email_id){
sendgrid.send({
        to: email_id,
        from: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a6f7c6f647e794a5a78657a6f787e734d7f787f2469656724796d" rel="noreferrer noopener nofollow">[email protected]</a>',
        fromname: 'PropertyGuru Events',
        subject: 'Thank you for registering to visit Philippine Property Show 2014',
        html: html_content;
    }, function(err, json) {
        if (err) { return console.error(err); }
        console.log(json);
    });


 }

但是每次我运行这个,我都会收到错误 -

 +"<br> <br>Thank you once again and see you at the event.<br><br>
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/bhagabanbehera/extra/pguru/app.js:7:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

显然它无法识别我将 HTML 代码转储到 js 变量中。我该如何执行此操作 - 使用模板通过 sendgrid 发送电子邮件?

最佳答案

返回错误是因为您无法使用回车符来中断字符串html_content。将变量更改为以下内容:

var html_content = "Thank you for registering to visit Philippine Property Show 2014 organised by "
 +"PropertyGuru. This is the confirmation letter to your registration. Kindly present this letter at the registration counter for your entry to the event."
 +"<br><br>Thank you once again and see you at the event.<br><br>"
 +"<strong>Philippine Property Show</strong><br><strong>29 - 30 November 2013</strong>"
 +"<br><strong>Orchard Hotel, Level 2, Conference Centre<br></strong><br>"
 +"<strong><span>With Warm Regards,</span></strong><span><br><br></span>"
 +"<strong><span>PropertyGuru Events</span></strong><span><br><br>";

此外,删除 html: html_content 之后的 sendgrid.send 内的分号,它应该可以工作。

关于html - 如何在使用 Nodejs 时使用 SendGrid 的电子邮件模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22568007/

相关文章:

html - Link_to 方法不适用于 CSS

javascript - 使用 CTR 模式对 crypto-js 进行加密并在 Node crypto 上进行解密问题

html - 将图像 float 到列表中 anchor 的右侧

jquery - 如何将 jQuery UI 内容背景更改为白色?

node.js - AWS Lambda 上 NodeJS EventEmitter 中的异步函数

Node.js MEAN Stack 应用程序在本地工作,但无法部署到 Heroku

python - Heroku Python 远程拒绝错误

ruby-on-rails - 如何在 Rails 中通过电子邮件发送自生成的 csv 文件而不保存它?

android - Phonegap - 在 phonegap.com 上与本地构建时高度不同?

javascript - 如何在 Jade 中为每个项目呈现一个具有不同 javascript 函数的列表?