Implement SMTP email service (#28)
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var swig = require('swig');
|
||||
const config = require('config');
|
||||
const nodemailer = require('nodemailer');
|
||||
const swig = require('swig');
|
||||
//var AWS = require('aws-sdk');
|
||||
|
||||
module.exports = {
|
||||
sendMail: (to_email, subject, body, options) => {
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
// FIXME
|
||||
const teamname = options.teamname || "My Open Spacedeck"
|
||||
const from = teamname + ' <support@example.org>';
|
||||
const teamname = options.teamname || config.get('team_name');
|
||||
const from = teamname + ' <' + config.get('contact_email') + '>';
|
||||
|
||||
let reply_to = [from];
|
||||
if (options.reply_to) {
|
||||
@@ -29,9 +29,40 @@ module.exports = {
|
||||
options: options
|
||||
});
|
||||
|
||||
//if (process.env.NODE_ENV === 'development') {
|
||||
if (config.get('mail_provider') === 'console') {
|
||||
|
||||
console.log("Email: to " + to_email + " in production.\nreply_to: " + reply_to + "\nsubject: " + subject + "\nbody: \n" + htmlText + "\n\n plaintext:\n" + plaintext);
|
||||
/*} else {
|
||||
|
||||
} else if (config.get('mail_provider') === 'smtp') {
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: config.get('mail_smtp_host'),
|
||||
port: config.get('mail_smtp_port'),
|
||||
secure: config.get('mail_smtp_secure'),
|
||||
requireTLS: config.get('mail_smtp_require_tls'),
|
||||
auth: {
|
||||
user: config.get('mail_smtp_user'),
|
||||
pass: config.get('mail_smtp_pass'),
|
||||
}
|
||||
});
|
||||
|
||||
transporter.sendMail({
|
||||
from: from,
|
||||
replyTo: reply_to,
|
||||
to: to_email,
|
||||
subject: subject,
|
||||
text: plaintext,
|
||||
html: htmlText,
|
||||
}, function(err, info) {
|
||||
if (err) {
|
||||
console.error("Error sending email:", err);
|
||||
} else {
|
||||
console.log("Email sent.");
|
||||
}
|
||||
});
|
||||
|
||||
} else if (config.get('mail_provider') === 'aws') {
|
||||
/*
|
||||
AWS.config.update({region: 'eu-west-1'});
|
||||
var ses = new AWS.SES();
|
||||
|
||||
@@ -56,6 +87,7 @@ module.exports = {
|
||||
if (err) console.error("Error sending email:", err);
|
||||
else console.log("Email sent.");
|
||||
});
|
||||
}*/
|
||||
*/
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user