Austin Bratcher ddc01eb27b Update to add dynamic settings to email plugin
Email plugin now functions more like the upload plugin. Users can go to the plugins page, click on the settings cog for the email, and switch between providers or change settings. The default provider is strapi-email-sendmail. Extra providers can be added by installing strapi-email-mailgun or strapi-email-sendgrid.
2018-05-31 14:29:00 -05:00

71 lines
1.7 KiB
JavaScript

'use strict';
/**
* Module dependencies
*/
// Public node modules.
const _ = require('lodash');
const mailgunFactory = require('mailgun-js');
/* eslint-disable no-unused-vars */
module.exports = {
provider: 'mailgun',
name: 'Mailgun',
auth: {
mailgun_default_from: {
label: 'Mailgun Default From',
type: 'text'
},
mailgun_default_replyto: {
label: 'Mailgun Default Reply-To',
type: 'text'
},
mailgun_api_key: {
label: 'Mailgun API Key',
type: 'text'
},
mailgun_domain: {
label: 'Mailgun Domain',
type: 'text'
}
},
init: (config) => {
const mailgun = mailgunFactory({
apiKey: config.mailgun_api_key,
domain: config.mailgun_domain,
mute: false
});
return {
send: (options, cb) => {
return new Promise((resolve, reject) => {
// Default values.
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 = {
from: options.from,
to: options.to,
subject: options.subject,
text: options.text,
html: options.html
};
msg['h:Reply-To'] = options.replyTo;
mailgun.messages().send(msg, function (err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
});
});
}
};
}
};