Save current state (unmerged, broken, not working...)
[vchess.git] / utils / mailer.js.dist
1 const nodemailer = require('nodemailer');
2
3 const contact = "your_contact_email";
4
5 const send = function(from, to, subject, body, cb)
6 {
7 // Create reusable transporter object using the default SMTP transport
8 const transporter = nodemailer.createTransport({
9 host: "smtp_host_address",
10 port: 465, //if secure; otherwise use 587
11 secure: true,
12 auth: {
13 user: "user_name",
14 pass: "user_password"
15 }
16 });
17
18 // Setup email data with unicode symbols
19 const mailOptions = {
20 from: from, //note: some SMTP serves might forbid this
21 to: to,
22 subject: subject,
23 text: body,
24 };
25
26 // Avoid the actual sending in development mode
27 const env = process.env.NODE_ENV || 'development';
28 if ('development' === env)
29 {
30 console.log("New mail: from " + from + " / to " + to);
31 console.log("Subject: " + subject);
32 let msgText = body.split('\\n');
33 msgText.forEach(msg => { console.log(msg); });
34 return cb();
35 }
36
37 // Send mail with the defined transport object
38 transporter.sendMail(mailOptions, (error, info) => {
39 if (!!error)
40 return cb(error);
41 // Ignore info. Option:
42 //console.log('Message sent: %s', info.messageId);
43 return cb();
44 });
45 };
46
47 module.exports = {
48 contact: contact,
49 send: send
50 };