Transactional mail: use tools to format message
This commit is contained in:
parent
76b4f8b8c2
commit
e588e218b6
2 changed files with 18 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const mailers = require('./mailers');
|
||||
const tools = require('./tools');
|
||||
const templates = require('../models/templates');
|
||||
|
||||
class TemplateSender {
|
||||
|
@ -21,11 +22,13 @@ class TemplateSender {
|
|||
templates.getById(options.context, this.templateId, false)
|
||||
]);
|
||||
|
||||
const html = this._substituteVariables(
|
||||
const html = tools.formatTemplate(
|
||||
template.html,
|
||||
options.variables
|
||||
null,
|
||||
options.variables,
|
||||
true
|
||||
);
|
||||
const subject = this._substituteVariables(
|
||||
const subject = tools.formatTemplate(
|
||||
options.subject || template.description || template.name,
|
||||
options.variables
|
||||
);
|
||||
|
@ -63,17 +66,6 @@ class TemplateSender {
|
|||
throw new Error('Missing locale');
|
||||
}
|
||||
}
|
||||
|
||||
_substituteVariables(html, variables) {
|
||||
if (!variables) {
|
||||
return html;
|
||||
}
|
||||
return Object.keys(variables).reduce(
|
||||
(res, key) =>
|
||||
res.replace(new RegExp(`\\[${key}\\]`, 'gmi'), variables[key]),
|
||||
html
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TemplateSender;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue