2020-03-20 14:02:47 +01:00

61 lines
1.5 KiB
JavaScript

'use strict';
/**
* Module dependencies
*/
// Public node modules.
const _ = require('lodash');
const sendmail = require('sendmail')({
silent: true,
});
/* eslint-disable no-unused-vars */
module.exports = {
provider: 'sendmail',
name: 'Sendmail',
auth: {
sendmail_default_from: {
label: 'Sendmail Default From',
type: 'text',
},
sendmail_default_replyto: {
label: 'Sendmail Default Reply-To',
type: 'text',
},
},
init: config => {
return {
send: options => {
return new Promise((resolve, reject) => {
// Default values.
options = _.isObject(options) ? options : {};
options.from = options.from || config.sendmail_default_from;
options.replyTo = options.replyTo || config.sendmail_default_replyto;
options.text = options.text || options.html;
options.html = options.html || options.text;
sendmail(
{
from: options.from,
to: options.to,
replyTo: options.replyTo,
subject: options.subject,
text: options.text,
html: options.html,
attachments: options.attachments,
},
function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
}
);
});
},
};
},
};