-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
29 lines (26 loc) · 748 Bytes
/
utils.js
File metadata and controls
29 lines (26 loc) · 748 Bytes
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
const nodemailer = require("nodemailer");
// Create a Nodemailer transporter using Gmail and App Password
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.NODE_MAILER_EMAIL,
pass: process.env.NODE_MAILER_PASSWORD,
},
});
/**
* Sends an email using the provided options
* @param {Object} mailOptions - Email options such as 'to', 'subject', 'html', 'text'
* @returns {Promise<void>}
*/
const sendEmail = async (mailOptions) => {
try {
await transporter.sendMail(mailOptions);
console.log("Email sent successfully.");
} catch (error) {
console.error("Error sending email:", error);
throw new Error("Email sending failed");
}
};
module.exports = {
sendEmail,
};