diff --git a/supabase/functions/send-smtp-email/index.ts b/supabase/functions/send-smtp-email/index.ts index 24c5f0a..802b466 100644 --- a/supabase/functions/send-smtp-email/index.ts +++ b/supabase/functions/send-smtp-email/index.ts @@ -62,11 +62,25 @@ Deno.serve(async (req) => { return json({ error: "to and subject are required" }, 400); } + // Auto-correct common TLS misconfigurations: + // - Port 465 always uses implicit TLS (tls: true) + // - Port 587 / 25 use STARTTLS (tls: false; denomailer upgrades automatically) + let useTls = !!settings.secure; + if (settings.port === 465) useTls = true; + else if (settings.port === 587 || settings.port === 25) useTls = false; + + console.log("SMTP connecting", { + host: settings.host, + port: settings.port, + tls: useTls, + hasAuth: !!settings.username, + }); + const client = new SMTPClient({ connection: { hostname: settings.host, port: settings.port, - tls: !!settings.secure, + tls: useTls, auth: settings.username ? { username: settings.username, password } : undefined,