2020-10-29 13:45:47 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
const nodemailer = require('nodemailer');
|
|
|
|
|
2020-11-09 15:51:03 +01:00
|
|
|
const emailFields = [
|
|
|
|
'from',
|
|
|
|
'replyTo',
|
|
|
|
'to',
|
|
|
|
'cc',
|
|
|
|
'bcc',
|
|
|
|
'subject',
|
|
|
|
'text',
|
|
|
|
'html',
|
|
|
|
'attachments',
|
|
|
|
];
|
|
|
|
|
2020-10-29 13:45:47 +01:00
|
|
|
module.exports = {
|
|
|
|
provider: 'nodemailer',
|
|
|
|
name: 'Nodemailer',
|
|
|
|
|
|
|
|
init: (providerOptions = {}, settings = {}) => {
|
|
|
|
const transporter = nodemailer.createTransport(providerOptions);
|
|
|
|
|
|
|
|
return {
|
|
|
|
send: options => {
|
2020-11-09 15:51:03 +01:00
|
|
|
// Default values.
|
|
|
|
options = _.isObject(options) ? options : {};
|
|
|
|
options.from = options.from || settings.defaultFrom;
|
|
|
|
options.replyTo = options.replyTo || settings.defaultReplyTo;
|
|
|
|
options.text = options.text || options.html;
|
|
|
|
options.html = options.html || options.text;
|
2020-10-29 13:45:47 +01:00
|
|
|
|
2020-11-09 15:51:03 +01:00
|
|
|
return transporter.sendMail(_.pick(options, emailFields));
|
2020-10-29 13:45:47 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|