From 8ae05f40c4375388a64f728032d8f048eefe6deb Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Mon, 4 May 2026 21:01:24 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/email.ts | 91 ++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 54 deletions(-) diff --git a/frontend/src/lib/email.ts b/frontend/src/lib/email.ts index a18825d..e33115a 100644 --- a/frontend/src/lib/email.ts +++ b/frontend/src/lib/email.ts @@ -1,3 +1,4 @@ +import nodemailer from 'nodemailer'; import type { EmailOptions } from '../globalInterfaces'; const isDev = import.meta.env.DEV; @@ -7,6 +8,11 @@ const isProduction = hasProductionFlag || forceProduction || !isDev; const RESEND_API_KEY = isProduction ? (import.meta.env.RESEND_API_KEY || '') : ''; +const SMTP_HOST = isProduction ? (import.meta.env.SMTP_HOST || '') : ''; +const SMTP_PORT = isProduction ? (import.meta.env.SMTP_PORT || '465') : '1025'; +const SMTP_AUTH_USER = isProduction ? (import.meta.env.SMTP_AUTH_USER || '') : ''; +const SMTP_AUTH_PASS = isProduction ? (import.meta.env.SMTP_AUTH_PASS || '') : ''; + const FROM_EMAIL = isProduction ? (import.meta.env.FROM_EMAIL || 'noreply@localhost') : 'noreply@localhost'; @@ -17,12 +23,23 @@ const SITE_URL = isProduction console.log('[EMAIL] isDev:', isDev); console.log('[EMAIL] isProduction:', isProduction); -console.log('[EMAIL] Using Resend:', isProduction && !!RESEND_API_KEY); +console.log('[EMAIL] SMTP:', SMTP_HOST, ':', SMTP_PORT); + +function getTransporter() { + return nodemailer.createTransport({ + host: SMTP_HOST, + port: parseInt(SMTP_PORT), + secure: SMTP_PORT === '465', + connectionTimeout: 15000, + auth: SMTP_AUTH_USER ? { + user: SMTP_AUTH_USER, + pass: SMTP_AUTH_PASS, + } : undefined, + }); +} async function sendViaResend(options: EmailOptions): Promise { try { - console.log('[RESEND] Sending to:', options.to); - const response = await fetch('https://api.resend.com/emails', { method: 'POST', headers: { @@ -53,11 +70,27 @@ async function sendViaResend(options: EmailOptions): Promise { } export async function sendEmail(options: EmailOptions): Promise { + if (SMTP_HOST && SMTP_AUTH_PASS) { + try { + const info = await getTransporter().sendMail({ + from: `${FROM_NAME} <${FROM_EMAIL}>`, + to: options.to, + subject: options.subject, + html: options.html, + }); + console.log('[SMTP] Email sent:', info.messageId); + return true; + } catch (error) { + console.error('[SMTP] Email send error:', error); + return false; + } + } + if (isProduction && RESEND_API_KEY) { return sendViaResend(options); } - console.log('[DEV] Email not sent (no Resend key):', options.to); + console.log('[DEV] Email not sent:', options.to); return false; } @@ -79,28 +112,21 @@ export function generateVerifyEmailHtml(firstName: string, verifyLink: string): - - - - - - - - - -

Автоюрист Сургут

Юридические услуги для автовладельцев

Добро пожаловать, ${firstName}!

-

Благодарим за регистрацию на сайте avtourist-surgut.ru. Мы рады, что вы выбрали нас для решения юридических вопросов, связанных с автомобилем.

-

Для завершения регистрации и активации вашего аккаунта, пожалуйста, подтвердите ваш email, нажав на кнопку ниже:

- -
@@ -112,54 +138,11 @@ export function generateVerifyEmailHtml(firstName: string, verifyLink: string):
- - - - - - -
-
- - - -
-

Бесплатная консультация

-
-
- - - - - - -
-

Оплата за результат

-
-
- - - - -
-

Работаем 24/7

-
-

© 2026 Автоюрист Сургут. Все права защищены.

-

- Это письмо отправлено автоматически, пожалуйста, не отвечайте на него. -