38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
import nodemailer from 'nodemailer';
|
|
import DAORegistro from '../Controller/DAORegistro.js';
|
|
import logger from '../utils/logger.js';
|
|
|
|
class EmailCtrl {
|
|
static async sendEmail(req, res) {
|
|
const transporter = nodemailer.createTransport({
|
|
service: 'Gmail',
|
|
auth: {
|
|
user: 'drannet9@gmail.com',
|
|
pass: 'qnjkswqvuonuporj'
|
|
}
|
|
});
|
|
|
|
const mailOptions = {
|
|
from: 'drannet9@gmail.com',
|
|
to: req.body.correo,
|
|
subject: 'Registro',
|
|
text: 'Gracias por registrarse en Dran.net este es tu matricula: ' + req.body.matricula + ' y esta tu contraseña: ' + req.body.contrasena + ' No se te olvide anotarlas bien.'
|
|
};
|
|
|
|
try {
|
|
const info = await transporter.sendMail(mailOptions);
|
|
logger.info(`Email sent: ${info.response}`);
|
|
res.status(200).jsonp(req.body);
|
|
|
|
const descripcion = `Correo enviado a ${mailOptions.to}`;
|
|
const fecha = new Date();
|
|
await DAORegistro.registrar('SYSTEM', descripcion, fecha);
|
|
} catch (error) {
|
|
logger.error(`Error al enviar el correo: ${error}`);
|
|
res.status(500).send(error.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default EmailCtrl;
|