2017-04-07 01:29:05 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var swig = require('swig');
|
2018-04-12 16:38:48 +02:00
|
|
|
//var AWS = require('aws-sdk');
|
2017-04-07 01:29:05 +02:00
|
|
|
|
|
|
|
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>';
|
|
|
|
|
|
|
|
let reply_to = [from];
|
|
|
|
if (options.reply_to) {
|
|
|
|
reply_to = [options.reply_to];
|
|
|
|
}
|
|
|
|
|
|
|
|
let plaintext = body;
|
|
|
|
if (options.action && options.action.link) {
|
|
|
|
plaintext+="\n"+options.action.link+"\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
const htmlText = swig.renderFile('./views/emails/action.html', {
|
|
|
|
text: body.replace(/(?:\n)/g, '<br />'),
|
|
|
|
options: options
|
|
|
|
});
|
|
|
|
|
2018-04-12 16:38:48 +02:00
|
|
|
//if (process.env.NODE_ENV === 'development') {
|
2017-04-07 01:29:05 +02:00
|
|
|
console.log("Email: to " + to_email + " in production.\nreply_to: " + reply_to + "\nsubject: " + subject + "\nbody: \n" + htmlText + "\n\n plaintext:\n" + plaintext);
|
2018-04-12 16:38:48 +02:00
|
|
|
/*} else {
|
2017-04-07 01:29:05 +02:00
|
|
|
AWS.config.update({region: 'eu-west-1'});
|
|
|
|
var ses = new AWS.SES();
|
|
|
|
|
|
|
|
ses.sendEmail( {
|
|
|
|
Source: from,
|
|
|
|
Destination: { ToAddresses: [to_email] },
|
|
|
|
ReplyToAddresses: reply_to,
|
|
|
|
Message: {
|
|
|
|
Subject: {
|
|
|
|
Data: subject
|
|
|
|
},
|
|
|
|
Body: {
|
|
|
|
Text: {
|
|
|
|
Data: plaintext,
|
|
|
|
},
|
|
|
|
Html: {
|
|
|
|
Data: htmlText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, function(err, data) {
|
2018-03-30 22:34:27 +02:00
|
|
|
if (err) console.error("Error sending email:", err);
|
2017-04-07 01:29:05 +02:00
|
|
|
else console.log("Email sent.");
|
|
|
|
});
|
2018-04-12 16:38:48 +02:00
|
|
|
}*/
|
2017-04-07 01:29:05 +02:00
|
|
|
}
|
|
|
|
};
|