Commit | Line | Data |
---|---|---|
298c42e6 BA |
1 | const nodemailer = require('nodemailer'); |
2 | ||
3 | module.exports = function(email, subject, content, cb) | |
4 | { | |
5 | // create reusable transporter object using the default SMTP transport | |
6 | const transporter = nodemailer.createTransport({ | |
7 | host: "smtp_host_address", | |
8 | port: 465, //if secure; otherwise use 587 | |
9 | secure: true, | |
10 | auth: { | |
11 | user: "user_name", | |
12 | pass: "user_password" | |
13 | } | |
14 | }); | |
15 | ||
16 | // setup email data with unicode symbols | |
17 | const mailOptions = { | |
18 | from: email, //note: some SMTP serves might forbid this | |
19 | to: "contact_email", | |
20 | subject: subject, | |
21 | text: content, | |
22 | }; | |
23 | ||
24 | // send mail with defined transport object | |
25 | transporter.sendMail(mailOptions, (error, info) => { | |
26 | if (!!error) | |
27 | return cb(error); | |
28 | // Ignore info. Option: | |
29 | //console.log('Message sent: %s', info.messageId); | |
30 | return cb(); | |
31 | }); | |
32 | }; |