javascript - Sendgrid: render an ejs template and then send as an email. -
so have index.ejs renders when start nodejs server:
<!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 did not validate: </h1> <ul> <% for(var i=0; i<unvalid.length; i++) {%> <li><%= unvalid[i] %></li> <% } %> </ul> </body> </html>
the thing is, send on email using sendgrid. far i've been doing using .sethtml method sort of "brute-force" it:
email.sethtml('<h1> spotluck daily report </h1><h3>'+ yesterday + '</h3><h1> number of spins: '+cuenta+'</h1><h1> active user count: '+usercount+'</h1>' +'<h1> users did not validate: </h1>');
but never work because unable render ejs loop. question is: how tell sendgrid email render ejs , send email without having resort .sethtml?
you can achieve using ejs.render(str, subs)
function inside of sethtml
.
email.sethtml(ejs.render(yourtemplate, {foo: 'bar'}));
but i'd recommend using sendgrid's template engine since our node library supports it.
Comments
Post a Comment