From 1eedeb9fb916d7058372523cc7a083897c323700 Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Mon, 4 May 2026 03:39:36 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/email.ts | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/email.ts b/frontend/src/lib/email.ts index c8cd830..2f5d757 100644 --- a/frontend/src/lib/email.ts +++ b/frontend/src/lib/email.ts @@ -8,7 +8,7 @@ const SMTP_HOST = isProduction ? (import.meta.env.SMTP_HOST || 'smtp.resend.com') : 'localhost'; const SMTP_PORT = isProduction - ? (import.meta.env.SMTP_PORT || '465') + ? (import.meta.env.SMTP_PORT || '587') : '1025'; const SMTP_AUTH_USER = isProduction ? (import.meta.env.SMTP_AUTH_USER || '') : ''; const SMTP_AUTH_PASS = isProduction ? (import.meta.env.SMTP_AUTH_PASS || '') : ''; @@ -27,11 +27,14 @@ console.log('[EMAIL] SMTP config:', { host: SMTP_HOST, port: SMTP_PORT, auth: !! function getTransporter() { if (!transporter) { + const useTLS = SMTP_PORT === '465'; transporter = nodemailer.createTransport({ host: SMTP_HOST, port: parseInt(SMTP_PORT), - secure: isProduction, - requireTLS: isProduction, + secure: useTLS, + requireTLS: !useTLS, + connectionTimeout: 10000, + greetingTimeout: 10000, auth: isProduction && SMTP_AUTH_USER ? { user: SMTP_AUTH_USER, pass: SMTP_AUTH_PASS, @@ -41,17 +44,29 @@ function getTransporter() { return transporter; } +function withTimeout(promise: Promise, ms: number): Promise { + return Promise.race([ + promise, + new Promise((_, reject) => + setTimeout(() => reject(new Error('Email send timeout')), ms) + ) + ]); +} + export async function sendEmail(options: EmailOptions): Promise { try { console.log('Sending email to:', options.to); console.log('SMTP config:', { host: SMTP_HOST, port: SMTP_PORT }); - const info = await getTransporter().sendMail({ - from: `${FROM_NAME} <${FROM_EMAIL}>`, - to: options.to, - subject: options.subject, - html: options.html, - }); + const info = await withTimeout( + getTransporter().sendMail({ + from: `${FROM_NAME} <${FROM_EMAIL}>`, + to: options.to, + subject: options.subject, + html: options.html, + }), + 15000 + ); console.log('Email sent:', info.messageId); return true;