Servidor/utils/sendEmail.js

47 lines
1.4 KiB
JavaScript

const nodemailer = require("nodemailer");
require("dotenv").config();
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
async function sendVerificationEmail(to, token) {
const verificationUrl = `${process.env.CLIENT_URL}/users/verify-email/${token}`;
const mailOptions = {
from: `YomiTrack <${process.env.EMAIL_USER}>`,
to,
subject: "Verifica tu cuenta en YomiTrack",
html: `
<h3>Bienvenido a YomiTrack!</h3>
<p>Haz clic en el siguiente enlace para verificar tu cuenta:</p>
<a href="${verificationUrl}" target="_blank">Verificar cuenta</a>
<p>Si tú no solicitaste esta cuenta, puedes ignorar este mensaje.</p>
`,
};
return transporter.sendMail(mailOptions);
}
async function sendResetEmail(to, token, email) {
const resetUrl = `${process.env.CLIENT_URL}/reset-password.html?token=${token}&email=${email}`;
const html = `
<p>Haz clic en el siguiente enlace para restablecer tu contraseña:</p>
<a href="${resetUrl}">${resetUrl}</a>
`;
await transporter.sendMail({
from: `YomiTrack <${process.env.EMAIL_USER}>`,
to,
subject: 'Restablece tu contraseña',
html
});
}
module.exports = {
sendVerificationEmail,
sendResetEmail
};