X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Futils%2Fmailer.js;h=60cc9f26d66974018fc726c90d3888f89bdc069f;hp=86e647c2a1776b0c40307680d9ebcd67617e4b52;hb=a749972cf93fd021dda11389753ae4985ff61b42;hpb=58e7b94e6e1a8d5721b9211b45c40e65fc13f600 diff --git a/server/utils/mailer.js b/server/utils/mailer.js index 86e647c2..60cc9f26 100644 --- a/server/utils/mailer.js +++ b/server/utils/mailer.js @@ -3,42 +3,45 @@ const params = require("../config/parameters"); module.exports = function(from, to, subject, body, cb) { - // Avoid the actual sending in development mode - if (params.env === 'development') - { - console.log("New mail: from " + from + " / to " + to); - console.log("Subject: " + subject); - let msgText = body.split('\\n'); - msgText.forEach(msg => { console.log(msg); }); - return cb(); - } + // Avoid the actual sending in development mode + if (params.env === 'development') + { + console.log("New mail: from " + from + " / to " + to); + console.log("Subject: " + subject); + console.log(body); + if (!cb) + cb = (err) => { if (!!err) console.log(err); } + return cb(); + } + else if (!cb) + cb = () => {}; //default: do nothing (TODO: log somewhere) // Create reusable transporter object using the default SMTP transport - const transporter = nodemailer.createTransport({ - host: params.mail.host, - port: params.mail.port, - secure: params.mail.secure, - auth: { - user: params.mail.user, - pass: params.mail.pass - } - }); + const transporter = nodemailer.createTransport({ + host: params.mail.host, + port: params.mail.port, + secure: params.mail.secure, + auth: { + user: params.mail.user, + pass: params.mail.pass + } + }); - // Setup email data with unicode symbols - const mailOptions = { - from: params.mail.noreply, - to: to, - subject: subject, - text: body, + // Setup email data with unicode symbols + const mailOptions = { + from: params.mail.noreply, + to: to, + subject: subject, + text: body, replyTo: from, }; - // Send mail with the defined transport object - transporter.sendMail(mailOptions, (error, info) => { - if (!!error) - return cb(error); + // Send mail with the defined transport object + transporter.sendMail(mailOptions, (error, info) => { + if (!!error) + return cb(error); // Ignore info. Option: - //console.log('Message sent: %s', info.messageId); - return cb(); + //console.log('Message sent: %s', info.messageId); + return cb(); }); }