27 lines
559 B
JavaScript
27 lines
559 B
JavaScript
const nodemailer = require("nodemailer");
|
|
|
|
exports.sendEmail = async (to, subject, body) => {
|
|
|
|
const port = Number(process.env.MAIL_PORT);
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
|
|
host: process.env.MAIL_HOST,
|
|
port,
|
|
secure: port === 465, // SSL
|
|
requireTLS: port === 587, // Enforce TLS for 587
|
|
auth: {
|
|
user: process.env.MAIL_USER,
|
|
pass: process.env.MAIL_PASS,
|
|
},
|
|
|
|
});
|
|
|
|
await transporter.sendMail({
|
|
from: process.env.SMTP_FROM || process.env.SMTP_USER,
|
|
to,
|
|
subject,
|
|
html: body,
|
|
});
|
|
};
|