First upload
This commit is contained in:
47
server/services/mail.service.js
Normal file
47
server/services/mail.service.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
|
||||
// Configuración del transportador
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.db, // Nota: Asegúrate de que esta variable sea el host SMTP (ej. smtp.tuproveedor.com)
|
||||
port: 587,
|
||||
secure: false, // true para 465, false para otros puertos
|
||||
auth: {
|
||||
user: "natxocc",
|
||||
pass: "Ncc629406731.",
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Envía un correo electrónico
|
||||
* @param {string} to - Destinatario
|
||||
* @param {string} subject - Asunto
|
||||
* @param {string} html - Cuerpo en HTML
|
||||
* @param {Object|null} file - Opcional: { filename, content, contentType }
|
||||
*/
|
||||
export const send = async (to, subject, html, file = null) => {
|
||||
|
||||
const mailOptions = {
|
||||
from: '"Natxocc" <natxocc@natxocc.com>',
|
||||
to,
|
||||
subject,
|
||||
html,
|
||||
};
|
||||
|
||||
// Si pasas un archivo (ej: buffer de Sharp), lo añadimos como attachment
|
||||
if (file) {
|
||||
mailOptions.attachments = [
|
||||
{
|
||||
filename: file.filename,
|
||||
content: file.content,
|
||||
contentType: file.contentType || 'image/jpeg'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
await transporter.sendMail(mailOptions);
|
||||
} catch (error) {
|
||||
console.error('Error enviando email:', error);
|
||||
throw error; // Re-lanzamos para que la ruta de Hono capture el error
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user