diff --git a/modules/rcart/mod.ts b/modules/rcart/mod.ts index 6467fa5..e67a3d7 100644 --- a/modules/rcart/mod.ts +++ b/modules/rcart/mod.ts @@ -49,15 +49,21 @@ let _smtpTransport: Transporter | null = null; function getSmtpTransport(): Transporter | null { if (_smtpTransport) return _smtpTransport; - if (!process.env.SMTP_PASS) return null; + const host = process.env.SMTP_HOST || "mail.rmail.online"; + const isInternal = host.includes('mailcow') || host.includes('postfix'); + if (!process.env.SMTP_PASS && !isInternal) return null; + // Internal mailcow network: relay on port 25 without auth + // External: use port 587 with STARTTLS + auth _smtpTransport = createTransport({ - host: process.env.SMTP_HOST || "mail.rmail.online", - port: Number(process.env.SMTP_PORT) || 587, - secure: Number(process.env.SMTP_PORT) === 465, - auth: { - user: process.env.SMTP_USER || "noreply@rmail.online", - pass: process.env.SMTP_PASS, - }, + host, + port: isInternal ? 25 : (Number(process.env.SMTP_PORT) || 587), + secure: !isInternal && Number(process.env.SMTP_PORT) === 465, + ...(isInternal ? {} : { + auth: { + user: process.env.SMTP_USER || "noreply@rmail.online", + pass: process.env.SMTP_PASS!, + }, + }), tls: { rejectUnauthorized: false }, }); return _smtpTransport;