fix(#4537): add support for Mailgun templates and variables

This commit is contained in:
Mickael Dacosta 2019-11-15 17:49:01 +01:00
parent c603ec3499
commit 4fc713e7e6
2 changed files with 11 additions and 11 deletions

View File

@ -1,4 +1,4 @@
# strapi-provider-email-sendmail # strapi-provider-email-mailgun
## Resources ## Resources

View File

@ -6,7 +6,7 @@
/* eslint-disable prefer-template */ /* eslint-disable prefer-template */
// Public node modules. // Public node modules.
const _ = require('lodash'); const isObject = require('lodash/isObject');
const mailgunFactory = require('mailgun-js'); const mailgunFactory = require('mailgun-js');
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
@ -47,21 +47,21 @@ module.exports = {
send: (options, cb) => { send: (options, cb) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Default values. // Default values.
options = _.isObject(options) ? options : {}; options = isObject(options) ? options : {};
options.from = options.from || config.mailgun_default_from;
options.replyTo = options.replyTo || config.mailgun_default_replyto;
options.text = options.text || options.html;
options.html = options.html || options.text;
let msg = { let msg = {
from: options.from, from: options.from || config.mailgun_default_from,
to: options.to, to: options.to,
subject: options.subject, subject: options.subject,
text: options.text, ...(options.text && { text: options.text }),
html: options.html, ...(options.html && { html: options.html }),
...(options.template && { template: options.template }),
...(options['h:X-Mailgun-Variables'] && {
'h:X-Mailgun-Variables': options['h:X-Mailgun-Variables'],
}),
...(options.attachment && { attachment: options.attachment }), ...(options.attachment && { attachment: options.attachment }),
}; };
msg['h:Reply-To'] = options.replyTo; msg['h:Reply-To'] = options.replyTo || config.mailgun_default_replyto;
mailgun.messages().send(msg, function(err) { mailgun.messages().send(msg, function(err) {
if (err) { if (err) {