我有一个 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/