Fix disconnexion => remove challenges in main Hall
[vchess.git] / server / utils / mailer.js
CommitLineData
8d7e2786 1const nodemailer = require('nodemailer');
0bd5933d 2const params = require("../config/parameters");
8d7e2786 3
0234201f 4module.exports = function(from, to, subject, body, cb) {
dac39588 5 // Avoid the actual sending in development mode
0234201f 6 if (params.env === 'development') {
dac39588
BA
7 console.log("New mail: from " + from + " / to " + to);
8 console.log("Subject: " + subject);
a749972c 9 console.log(body);
0234201f 10 if (!cb) cb = (err) => { if (err) console.log(err); }
866842c3
BA
11 cb();
12 return;
dac39588 13 }
866842c3
BA
14
15 // Production-only code from here:
16
0234201f
BA
17 // Default: do nothing (TODO: log somewhere)
18 if (!cb) cb = () => {};
c018b304 19
8d7e2786 20 // Create reusable transporter object using the default SMTP transport
dac39588
BA
21 const transporter = nodemailer.createTransport({
22 host: params.mail.host,
23 port: params.mail.port,
24 secure: params.mail.secure,
25 auth: {
26 user: params.mail.user,
27 pass: params.mail.pass
28 }
29 });
8d7e2786 30
dac39588
BA
31 // Setup email data with unicode symbols
32 const mailOptions = {
33 from: params.mail.noreply,
34 to: to,
35 subject: subject,
36 text: body,
58e7b94e 37 replyTo: from,
8d7e2786
BA
38 };
39
dac39588
BA
40 // Send mail with the defined transport object
41 transporter.sendMail(mailOptions, (error, info) => {
8d7e2786 42 // Ignore info. Option:
dac39588 43 //console.log('Message sent: %s', info.messageId);
866842c3 44 cb(error);
8d7e2786 45 });
0bd5933d 46}