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',
|
|
|
|
|
2021-09-13 12:03:12 +02:00
|
|
|
init(providerOptions = {}, settings = {}) {
|
2020-10-29 13:45:47 +01:00
|
|
|
const transporter = nodemailer.createTransport(providerOptions);
|
|
|
|
|
|
|
|
return {
|
2021-09-13 12:03:12 +02:00
|
|
|
send(options) {
|
2020-11-09 15:51:03 +01:00
|
|
|
// Default values.
|
2020-11-09 16:32:56 +01:00
|
|
|
const emailOptions = {
|
|
|
|
..._.pick(options, emailFields),
|
|
|
|
from: options.from || settings.defaultFrom,
|
|
|
|
replyTo: options.replyTo || settings.defaultReplyTo,
|
|
|
|
text: options.text || options.html,
|
|
|
|
html: options.html || options.text,
|
|
|
|
};
|
2020-10-29 13:45:47 +01:00
|
|
|
|
2020-11-09 16:32:56 +01:00
|
|
|
return transporter.sendMail(emailOptions);
|
2020-10-29 13:45:47 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|