X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Futils%2Fmailer.js;fp=server%2Futils%2Fmailer.js;h=8a059da28c8c935a19f7bb64a20a780cd37713ca;hb=625022fdcf750f0aff8fcd699f7e9b89730e1d10;hp=0000000000000000000000000000000000000000;hpb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;p=vchess.git diff --git a/server/utils/mailer.js b/server/utils/mailer.js new file mode 100644 index 00000000..8a059da2 --- /dev/null +++ b/server/utils/mailer.js @@ -0,0 +1,43 @@ +const nodemailer = require('nodemailer'); +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(); + } + + // 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 + } + }); + + // Setup email data with unicode symbols + const mailOptions = { + from: from, //note: some SMTP serves might forbid this + to: to, + subject: subject, + text: body, + }; + + // 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(); + }); +}