diff --git a/src/utils/email-handler.ts b/src/utils/email-handler.ts index 69e1246..a5f4b4e 100644 --- a/src/utils/email-handler.ts +++ b/src/utils/email-handler.ts @@ -32,47 +32,33 @@ let transporter: nodemailer.Transporter; // Initialize the transporter based on environment function initializeTransporter() { - if (isProduction && SMTP_HOST && SMTP_USER && SMTP_PASS) { - // Production: Use SMTP server - - // ProtonMail specific configuration - // ProtonMail often requires using their Bridge application for SMTP - const isProtonMail = SMTP_HOST.includes('protonmail'); - + if (isProduction && SMTP_HOST) { + // Use local Postfix mail relay (no authentication) transporter = nodemailer.createTransport({ host: SMTP_HOST, - port: parseInt(SMTP_PORT, 10), - secure: parseInt(SMTP_PORT, 10) === 465, // true for 465, false for other ports - auth: { - user: SMTP_USER, - pass: SMTP_PASS, + port: parseInt(SMTP_PORT, 10) || 25, // default to port 25 if not set + secure: false, // No SSL for local relay + tls: { + rejectUnauthorized: false, // Accept self-signed certificates if present }, - // ProtonMail specific settings - ...(isProtonMail && { - tls: { - // Do not fail on invalid certs - rejectUnauthorized: false, - // Specific ciphers for ProtonMail - ciphers: 'SSLv3', - }, - }), }); - // Verify SMTP connection configuration - transporter.verify(function (error, _success) { + transporter.verify((error, success) => { if (error) { - console.error('SMTP connection error:', error); + console.error('❌ SMTP connection error:', error); } else { - console.log('SMTP server is ready to take our messages'); + console.log('✅ SMTP server is ready to take messages.'); } }); } else { - // Development: Log emails to console + // Fallback for development: log email output to console transporter = nodemailer.createTransport({ streamTransport: true, newline: 'unix', buffer: true, }); + + console.log('⚠️ Email transporter using streamTransport (development mode)'); } }