I am using Keystone JS and nunjucks. I have a feature where in the application sends an email. There is no problem in sending the email , the problem is that the data does not pass to the template. It does not adapt.
var sendEmail = function (err, results) {
if (err) return callback(err);
async.each(results.admins, function (admin, done) {
new keystone.Email({ templateName: 'enquiry-notification.html', transport: 'mailgun', engine: cons.nunjucks, root: 'templates/emails' }).send({
}, {
apiKey: '',
domain: '',
title: "Test",
author: 'test',
body: 'Heeeeeeeeeeeeeeeeeeeeeeeeeeeee',
subject: subject,
html: '<b>NodeJS Email Tutorial</b>',
body: "Helloworld",
to: admin.email,
text: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavbbb',
host: 'helloworld.com',
from: {
name: 'Test Mail',
email: inquiry.email
},
inquiry: inquiry,
brand: brand,
}, done);
}, callback);
}
<h1>Hi %recipient%</h1>
<p class="text-larger">An enquiry was just submitted to %from.name%:</p>
{% if inquiry.email %}
<p class="text-larger">From
{% if inquiry.name.full %}
<strong>{{ inquiry.name.full }}</strong>
{% endif %}
{% endif %}
Because according to the doc, if you need to send locals you need to send it inside the .send()
method:
new Email(/* ... */).send({
recipient: {
firstName: 'Max',
name: 'Stoiber',
}
}, {/* ... */}, function (err, result) {/* ... */});
So in your case it will be:
const sendEmail = function (err, results) {
if (err) return callback(err);
async.each(results.admins, function (admin, done) {
new keystone.Email({ templateName: 'enquiry-notification.html', transport: 'mailgun', engine: cons.nunjucks, root: 'templates/emails' })
.send({
inquiry: inquiry,
brand: brand
}, { /*....*/ }, done);
}, callback);
}