gpt4 book ai didi

javascript - Sendgrid:渲染 ejs 模板,然后作为电子邮件发送。

转载 作者:行者123 更新时间:2023-11-28 19:06:20 25 4
gpt4 key购买 nike

所以我有index.ejs,当我启动我的nodejs服务器时,它可以完美呈现:

<!DOCTYPE html>
<html>
<head>
<title<%= title %></title>
</head>
<body>
<h1><%= title %></h1>
<h3><%= yesterday %></h3>
<h1> Number of Spins: <%= count %></h1>
<h1> Active User Count: <%= userCount %></h1>
<h1> Users that did not validate: </h1>
<ul>

<% for(var i=0; i<unvalid.length; i++) {%>

<li><%= unvalid[i] %></li>
<% } %>
</ul>
</body>
</html>

问题是,我想使用 Sendgrid 通过电子邮件发送此信息。到目前为止,我一直在使用 .setHTML 方法来“暴力破解”它:

email.setHtml('<h1> Spotluck Daily Report </h1><h3>'+ yesterday + '</h3><h1> Number of Spins: '+cuenta+'</h1><h1> Active User Count: '+userCount+'</h1>' +'<h1> Users that did not validate: </h1>');

但这永远不会起作用,因为它将无法渲染 ejs for 循环。所以我的问题是:如何告诉 Sendgrid 电子邮件呈现我的 ejs 并将其作为电子邮件发送,而不必求助于 .setHTML?

最佳答案

您可以使用ejs.render(str, subs) function 来实现此目的setHtml 内部。

email.setHtml(ejs.render(yourTemplate, {foo: 'bar'}));

但我建议使用 SendGrid 的 Template Engine由于我们的 Node 库 supports it .

关于javascript - Sendgrid:渲染 ejs 模板,然后作为电子邮件发送。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31592066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com