-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailService.js
40 lines (36 loc) · 992 Bytes
/
mailService.js
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
35
36
37
38
39
40
const nodemailer = require("nodemailer");
const sendMail = (emailAddress, emailData) => {
const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
port: 587,
secure: false, // Use `true` for port 465, `false` for all other ports
auth: {
user: process.env.TRANSPORTER_EMAIL,
pass: process.env.TRANSPORTER_PASS,
},
});
// verify connection configuration
transporter.verify(function (error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
//mail body
const mailBody = {
from: `"PocketCash" <${process.env.TRANSPORTER_EMAIL}>`,
to: emailAddress,
subject: emailData.subject,
html: emailData.message,
};
transporter.sendMail(mailBody, (error, info) => {
if (error) {
console.log(error);
} else {
console.log("Email Sent: " + info.response);
}
});
};
module.exports = sendMail;