From 913c7dc337658b3ff5950d16d4dbeeabab73d2e4 Mon Sep 17 00:00:00 2001
From: Alexey Zinkevych
curl -XGET '{getUrl(`api/rss/fetch/5OOnZKrp0?access_token=${accessToken}`)}'+ +
+ {t('sendSingleEmailByTemplateId')} +
+ ++ GET {t('arguments')} +
++ POST {t('arguments')} +
++ {t('example')} +
+ +curl -XPOST '{getUrl(`api/templates/1/send?access_token={accessToken}`)}' \ +--data 'EMAIL=test@example.com&SUBJECT=Test&VARIABLES[FOO]=bar&VARIABLES[TEST]=example'); } diff --git a/locales/en-US/common.json b/locales/en-US/common.json index ee60a4de..a5a10b28 100644 --- a/locales/en-US/common.json +++ b/locales/en-US/common.json @@ -964,5 +964,8 @@ "thePasswordMustContainAtLeastOne": "The password must contain at least one lowercase letter", "thePasswordMustContainAtLeastOne-1": "The password must contain at least one uppercase letter", "thePasswordMustContainAtLeastOneNumber": "The password must contain at least one number", - "thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character" + "thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character", + "templateVariables": "Map of template variables to replace", + "sendTransactionalEmail": "Send transactional email", + "sendSingleEmailByTemplateId": "Send single template by :templateId" } \ No newline at end of file diff --git a/locales/es-ES/common.json b/locales/es-ES/common.json index 980002e1..4a83ea90 100644 --- a/locales/es-ES/common.json +++ b/locales/es-ES/common.json @@ -964,6 +964,9 @@ "thePasswordMustContainAtLeastOne": "The password must contain at least one lowercase letter", "thePasswordMustContainAtLeastOne-1": "The password must contain at least one uppercase letter", "thePasswordMustContainAtLeastOneNumber": "The password must contain at least one number", - "thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character" + "thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character", + "templateVariables": "Map of template variables to replace", + "sendTransactionalEmail": "Send transactional email", + "sendSingleEmailByTemplateId": "Send single template by :templateId" } \ No newline at end of file From 80279346f346dea3a1490804c80f151b2b478967 Mon Sep 17 00:00:00 2001 From: Alexey Zinkevych
diff --git a/locales/en-US/common.json b/locales/en-US/common.json
index 20d5b6d9..7dcce754 100644
--- a/locales/en-US/common.json
+++ b/locales/en-US/common.json
@@ -965,7 +965,8 @@
"thePasswordMustContainAtLeastOne-1": "The password must contain at least one uppercase letter",
"thePasswordMustContainAtLeastOneNumber": "The password must contain at least one number",
"thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character",
- "templateVariables": "Map of template variables to replace",
+ "templateData": "Data passed to template when compiling with Handlebars",
+ "templateVariables": "Map of template/subject variables to replace",
"sendTransactionalEmail": "Send transactional email",
"sendSingleEmailByTemplateId": "Send single template by :templateId",
"sendConfigurationId": "ID of configuration used to create mailer instance"
diff --git a/locales/es-ES/common.json b/locales/es-ES/common.json
index 247b23b5..e26f9507 100644
--- a/locales/es-ES/common.json
+++ b/locales/es-ES/common.json
@@ -965,7 +965,8 @@
"thePasswordMustContainAtLeastOne-1": "The password must contain at least one uppercase letter",
"thePasswordMustContainAtLeastOneNumber": "The password must contain at least one number",
"thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character",
- "templateVariables": "Map of template variables to replace",
+ "templateData": "Data passed to template when compiling with Handlebars",
+ "templateVariables": "Map of template/subject variables to replace",
"sendTransactionalEmail": "Send transactional email",
"sendSingleEmailByTemplateId": "Send single template by :templateId",
"sendConfigurationId": "ID of configuration used to create mailer instance"
diff --git a/server/.eslintrc b/server/.eslintrc
index 91926fcd..360c05cb 100644
--- a/server/.eslintrc
+++ b/server/.eslintrc
@@ -1,3 +1,4 @@
{
- "extends": "nodemailer"
+ "extends": "nodemailer",
+ "parserOptions": { "ecmaVersion": 2017 }
}
diff --git a/server/lib/template-sender.js b/server/lib/template-sender.js
index 5ea4db67..d077f1b7 100644
--- a/server/lib/template-sender.js
+++ b/server/lib/template-sender.js
@@ -18,24 +18,25 @@ class TemplateSender {
const [mailer, template] = await Promise.all([
mailers.getOrCreateMailer(options.sendConfigurationId),
- templates.getById(
- options.context,
- this.templateId,
- false
- )
+ templates.getById(options.context, this.templateId, false)
]);
const html = this._substituteVariables(
template.html,
options.variables
);
+ const subject = this._substituteVariables(
+ options.subject || template.description || template.name,
+ options.variables
+ );
return mailer.sendTransactionalMail(
{
to: options.email,
- subject: options.subject
+ subject
},
{
html: { template: html },
+ data: options.data,
locale: options.locale
}
);
@@ -64,13 +65,14 @@ class TemplateSender {
}
_substituteVariables(html, variables) {
- if (!variables) return html;
- return Object.keys(variables).reduce((res, key) => {
- return res.replace(
- new RegExp(`\\[${key}\\]`, 'gmi'),
- variables[key]
- );
- }, html);
+ if (!variables) {
+ return html;
+ }
+ return Object.keys(variables).reduce(
+ (res, key) =>
+ res.replace(new RegExp(`\\[${key}\\]`, 'gmi'), variables[key]),
+ html
+ );
}
}
diff --git a/server/routes/api.js b/server/routes/api.js
index 60fa8a62..69a6b10b 100644
--- a/server/routes/api.js
+++ b/server/routes/api.js
@@ -303,6 +303,7 @@ router.postAsync('/templates/:templateId/send', async (req, res) => {
});
const info = await templateSender.send({
context: req.context,
+ data: input.DATA,
email: input.EMAIL,
locale: req.locale,
sendConfigurationId: input.SEND_CONFIGURATION_ID,
From e588e218b6ec90b12be34ec9f8e15298f6ec134e Mon Sep 17 00:00:00 2001
From: Alexey Zinkevych