Convert all remaining tabs by 2spaces
[vchess.git] / server / utils / mailer.js
1 const nodemailer = require('nodemailer');
2 const params = require("../config/parameters");
3
4 module.exports = function(from, to, subject, body, cb)
5 {
6 // Avoid the actual sending in development mode
7 if (params.env === 'development')
8 {
9 console.log("New mail: from " + from + " / to " + to);
10 console.log("Subject: " + subject);
11 let msgText = body.split('\\n');
12 msgText.forEach(msg => { console.log(msg); });
13 return cb();
14 }
15
16 // Create reusable transporter object using the default SMTP transport
17 const transporter = nodemailer.createTransport({
18 host: params.mail.host,
19 port: params.mail.port,
20 secure: params.mail.secure,
21 auth: {
22 user: params.mail.user,
23 pass: params.mail.pass
24 }
25 });
26
27 // Setup email data with unicode symbols
28 const mailOptions = {
29 from: params.mail.noreply,
30 to: to,
31 subject: subject,
32 text: body,
33 replyTo: from,
34 };
35
36 // Send mail with the defined transport object
37 transporter.sendMail(mailOptions, (error, info) => {
38 if (!!error)
39 return cb(error);
40 // Ignore info. Option:
41 //console.log('Message sent: %s', info.messageId);
42 return cb();
43 });
44 }