-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.js
35 lines (32 loc) · 1006 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
const nodemailer = require('nodemailer');
require('dotenv').config();
async function sendMail(options) {
try {
const transporter = nodemailer.createTransport({
service: process.env.service,
auth: {
user: process.env.USER,
pass: process.env.PASS,
}
})
const mailOption = await transporter.sendMail({
from: process.env.USER,
to: options.email,
subject: options.subject,
text: options.text,
html: options.html
});
await transporter.sendMail(mailOption);
return {
success: true,
message: 'Email sent successfully',
}
} catch (err) {
console.error('Error sending mail:', err.message);
return {
success: false,
message: 'Error sending mail: ' + err.message,
};
}
}
module.exports = sendMail;