fix: recorta espacios en host/usuario/remitente/destino de SMTP
Un espacio de mas en el host (tecleado por error, p.ej. "mail.linkedcorp. net") rompia la resolucion DNS sin ningun indicio visual del problema. Ahora se recorta con trim() antes de guardar o de probar, tanto en updateSmtpConfig como en testSmtpConfig. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,12 +31,15 @@ export async function getSmtpConfigInternal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function updateSmtpConfig(payload, actorId) {
|
export async function updateSmtpConfig(payload, actorId) {
|
||||||
if (!payload.host || !payload.user) throw new HttpError(400, 'Host y usuario son obligatorios');
|
const host = (payload.host || '').trim();
|
||||||
|
const user = (payload.user || '').trim();
|
||||||
|
const from = (payload.from || '').trim();
|
||||||
|
if (!host || !user) throw new HttpError(400, 'Host y usuario son obligatorios');
|
||||||
const entries = {
|
const entries = {
|
||||||
smtp_host: payload.host,
|
smtp_host: host,
|
||||||
smtp_port: String(payload.port || 587),
|
smtp_port: String(payload.port || 587),
|
||||||
smtp_user: payload.user,
|
smtp_user: user,
|
||||||
smtp_from: payload.from || payload.user,
|
smtp_from: from || user,
|
||||||
};
|
};
|
||||||
if (payload.pass) entries.smtp_pass_enc = encrypt(payload.pass);
|
if (payload.pass) entries.smtp_pass_enc = encrypt(payload.pass);
|
||||||
await repo.setMany(entries);
|
await repo.setMany(entries);
|
||||||
@@ -50,9 +53,12 @@ export async function updateSmtpConfig(payload, actorId) {
|
|||||||
// (credenciales invalidas, host inalcanzable, certificado vencido, etc.) — es una accion de
|
// (credenciales invalidas, host inalcanzable, certificado vencido, etc.) — es una accion de
|
||||||
// diagnostico explicita del superadmin, no un envio "de negocio".
|
// diagnostico explicita del superadmin, no un envio "de negocio".
|
||||||
export async function testSmtpConfig(payload, actorId) {
|
export async function testSmtpConfig(payload, actorId) {
|
||||||
const { to } = payload;
|
const to = (payload.to || '').trim();
|
||||||
|
const host = (payload.host || '').trim();
|
||||||
|
const user = (payload.user || '').trim();
|
||||||
|
const from = (payload.from || '').trim();
|
||||||
if (!to) throw new HttpError(400, 'Indica un correo destino para la prueba');
|
if (!to) throw new HttpError(400, 'Indica un correo destino para la prueba');
|
||||||
if (!payload.host || !payload.user) throw new HttpError(400, 'Host y usuario son obligatorios para probar');
|
if (!host || !user) throw new HttpError(400, 'Host y usuario son obligatorios para probar');
|
||||||
|
|
||||||
let pass = payload.pass;
|
let pass = payload.pass;
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
@@ -62,16 +68,16 @@ export async function testSmtpConfig(payload, actorId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
host: payload.host,
|
host,
|
||||||
port: Number(payload.port || 587),
|
port: Number(payload.port || 587),
|
||||||
secure: false,
|
secure: false,
|
||||||
requireTLS: true,
|
requireTLS: true,
|
||||||
auth: { user: payload.user, pass },
|
auth: { user, pass },
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await transporter.sendMail({
|
await transporter.sendMail({
|
||||||
from: payload.from || payload.user,
|
from: from || user,
|
||||||
to,
|
to,
|
||||||
subject: 'Correo de prueba — project.linkedcorp.net',
|
subject: 'Correo de prueba — project.linkedcorp.net',
|
||||||
html: '<p>Si estas leyendo esto, la configuracion SMTP de project.linkedcorp.net funciona correctamente.</p>',
|
html: '<p>Si estas leyendo esto, la configuracion SMTP de project.linkedcorp.net funciona correctamente.</p>',
|
||||||
|
|||||||
Reference in New Issue
Block a user