-
Notifications
You must be signed in to change notification settings - Fork 2
/
email.js
39 lines (35 loc) · 887 Bytes
/
email.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
import nodemailer from "nodemailer";
import dotenv from "dotenv";
dotenv.config();
const sendMail = async ({ to, link }, res) => {
var transporter = nodemailer.createTransport({
service: "gmail",
secure: false,
requireTLS: true,
auth: {
// eslint-disable-next-line no-undef
user: process.env.email,
// eslint-disable-next-line no-undef
pass: process.env.password,
},
});
var mailOptions = {
// eslint-disable-next-line no-undef
from: process.env.email,
to,
subject: "Password Reset",
text: `Your reset url is: ${link}`,
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
res.status(500);
res.end();
} else {
console.log("Email sent: " + info.response);
res.status(200);
res.end();
}
});
};
export default sendMail;