-
Notifications
You must be signed in to change notification settings - Fork 416
Expand file tree
/
Copy pathmailer.js
More file actions
34 lines (29 loc) · 1.11 KB
/
mailer.js
File metadata and controls
34 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const nodemailer = require("nodemailer");
// create reusable transporter object using the default SMTP transport
var mailConfig;
mailConfig = {
host: process.env.EMAIL_SMTP_HOST,
port: process.env.EMAIL_SMTP_PORT,
secure: process.env.EMAIL_SMTP_SECURE, // lack of ssl commented this. You can uncomment it.
auth: {
user: process.env.EMAIL_SMTP_USERNAME,
pass: process.env.EMAIL_SMTP_PASSWORD
}
};
let transporter = nodemailer.createTransport(mailConfig);
exports.send = async function (from, to, subject, html)
{
// send mail with defined transport object
// visit https://nodemailer.com/ for more options
var mailOptions = {
from: from, // sender address e.g. <foo@example.com>
to: to, // list of receivers e.g. bar@example.com, baz@example.com
subject: subject, // Subject line e.g. 'Hello ✔'
//text: text, // plain text body e.g. Hello world?
html: html // html body e.g. '<b>Hello world?</b>'
};
let email = await transporter.sendMail(mailOptions);
console.log("email id sent: %s", email.messageId);
console.log("email sent: %s", email);
console.log("email response sent: %s", email.response);
};