例如:我想向电子邮件验证失败的用户发送电子邮件。
我尝试过的...
authCtrl.js
const template = require('../templates')
let templateName = (success) ? 'templateEmailValidationConfirmation' :
'templateEmailValidationFailure';
let template = templates.getTemplate(templateName);
return emailHelper.compileMailContent(template.template);
emailHelper.js
const mustache = require('mustache');
const compileMailContent = (template) => {
let params ={
recipientName : 'Ajay'
}
const compileFunc = mustache.render(template, params);
console.log(compileFunc);
return compileFunc;
};
templates.js
const templateEmailValidationFailure =
'<!DOCTYPE html>\n' +
'\n' +
'<head>\n' +
' <title>Email Not verified</title>\n' +
'</head>\n' +
' <div>\n' +
' <h4 class="font-weight-bold text-danger">\n' +
' </i> Sorry {{recipientName}} ! Your mail could not be verified</h4>\n' +
' <hr/>\n' +
' <div>\n' +
' This could be because either your verification code is incorrect or the URL has expired
or has been mistyped.\n' +
' </div>\n' +
' </div>\n' +
'</div>';
const templates = [
{
id: 'templateEmailValidationFailure',
template: templateEmailValidationFailure
},
]
exports.getTemplate = (id) => {
return templates.find((obj) => {
return obj.id === id;
});
};
这使我从template.js中抛出错误-无法读取'recipientName'的属性。根据{C},HTML中使用的DOCUMENT参数显示在{{}}中。我的代码有什么问题?