using nodemaler and stmp
This commit is contained in:
Generated
+8
-6
@@ -24,6 +24,7 @@
|
||||
"mariadb": "^2.5.1",
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.4.2",
|
||||
"nodemailer": "^6.10.1",
|
||||
"sequelize": "^6.3.5",
|
||||
"validator": "^13.1.17"
|
||||
},
|
||||
@@ -1994,9 +1995,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "6.7.2",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz",
|
||||
"integrity": "sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q==",
|
||||
"version": "6.10.1",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.10.1.tgz",
|
||||
"integrity": "sha512-Z+iLaBGVaSjbIzQ4pX6XV41HrooLsQ10ZWPUehGmuantvzWoDVBnmsdUcOIDM1t+yPor5pDhVlDESgOMEGxhHA==",
|
||||
"license": "MIT-0",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
@@ -4525,9 +4527,9 @@
|
||||
"integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w=="
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.7.2",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz",
|
||||
"integrity": "sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q=="
|
||||
"version": "6.10.1",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.10.1.tgz",
|
||||
"integrity": "sha512-Z+iLaBGVaSjbIzQ4pX6XV41HrooLsQ10ZWPUehGmuantvzWoDVBnmsdUcOIDM1t+yPor5pDhVlDESgOMEGxhHA=="
|
||||
},
|
||||
"nodemon": {
|
||||
"version": "2.0.15",
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"mariadb": "^2.5.1",
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.4.2",
|
||||
"nodemailer": "^6.10.1",
|
||||
"sequelize": "^6.3.5",
|
||||
"validator": "^13.1.17"
|
||||
},
|
||||
|
||||
+45
-1
@@ -1,4 +1,4 @@
|
||||
require('../config/config');
|
||||
/* require('../config/config');
|
||||
|
||||
const send = require('gmail-send')({
|
||||
user: process.env.GMAIL,
|
||||
@@ -21,3 +21,47 @@ const gmail = (subject, to, text) => {
|
||||
};
|
||||
|
||||
module.exports = gmail;
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// src/utils/gmail.js (o donde prefieras)
|
||||
// gmail.js (o el nombre que prefieras)
|
||||
require('../config/config'); // mantiene tu carga de variables
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
// Transporter con pooling y throttling
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: 'smtp.gmail.com', // cambia a smtp-relay.gmail.com si usas Workspace
|
||||
port: 587,
|
||||
secure: false, // STARTTLS en puerto 587
|
||||
requireTLS: true,
|
||||
auth: {
|
||||
user: process.env.USER_GMAIL, // ejemplo: tu-cuenta@gmail.com
|
||||
pass: process.env.PASS_GMAIL, // App-Password de 16 caracteres
|
||||
},
|
||||
pool: true, // reutiliza la conexión
|
||||
maxConnections: 1, // una conexión simultánea
|
||||
maxMessages: 100, // reabre después de 100 envíos
|
||||
rateDelta: 2000, // ventana de 2 s
|
||||
rateLimit: 1, // máx. 1 mensaje por ventana (≈ 0.5 msg/s)
|
||||
});
|
||||
|
||||
/**
|
||||
* Envía un correo (API idéntica a tu versión anterior).
|
||||
* @param {string} subject Asunto
|
||||
* @param {string|string[]} to Destinatario(s)
|
||||
* @param {string} text Cuerpo en texto plano
|
||||
* @return {Promise<object>} info de nodemailer
|
||||
*/
|
||||
const gmail = (subject, to, text) =>
|
||||
transporter.sendMail({
|
||||
from: process.env.USER_GMAIL,
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
});
|
||||
|
||||
module.exports = gmail;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user