From 472dbeee8c53e2e4b96b960756047f59672eb652 Mon Sep 17 00:00:00 2001 From: nu-wa <32520539+nu-wa@users.noreply.github.com> Date: Sat, 13 Dec 2025 19:57:08 +0100 Subject: [PATCH] SMTP: support SMTPS on port 465 (#2132) * Add more configuration options for the SMTP connection * Add SMTP_TLS option for implicit TLS connections For SMTPS servers (typically port 465), set SMTP_TLS=true. Port auto-defaults to 465 when TLS is enabled, 587 otherwise. STARTTLS is used by default and automatically disabled when TLS is on. Fixes boolean conversion bug in original PR (string "false" is truthy) and removes insecure default for certificate verification. --------- Co-authored-by: Jeremy Daer --- config/environments/production.rb | 5 +++-- docs/docker-deployment.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 031c9d2cb..173318fe3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -11,12 +11,13 @@ Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: smtp_address, - port: ENV.fetch("SMTP_PORT", "587").to_i, + port: ENV.fetch("SMTP_PORT", ENV["SMTP_TLS"] == "true" ? "465" : "587").to_i, domain: ENV.fetch("SMTP_DOMAIN", nil), user_name: ENV.fetch("SMTP_USERNAME", nil), password: ENV.fetch("SMTP_PASSWORD", nil), authentication: ENV.fetch("SMTP_AUTHENTICATION", "plain"), - enable_starttls_auto: ENV.fetch("SMTP_ENABLE_STARTTLS_AUTO", "true") == "true" + tls: ENV["SMTP_TLS"] == "true", + openssl_verify_mode: ENV["SMTP_SSL_VERIFY_MODE"] } end diff --git a/docs/docker-deployment.md b/docs/docker-deployment.md index 15ec58367..f92b80ca2 100644 --- a/docs/docker-deployment.md +++ b/docs/docker-deployment.md @@ -78,14 +78,15 @@ You can then plug all your SMTP settings from that provider into Fizzy via the f - `MAILER_FROM_ADDRESS` - the "from" address that Fizzy should use to send email - `SMTP_ADDRESS` - the address of the SMTP server you'll send through -- `SMTP_PORT` - the port number you use to connect to that SMTP server (the default is 587) +- `SMTP_PORT` - the port number (defaults to 465 when `SMTP_TLS` is set, 587 otherwise) - `SMTP_USERNAME`/`SMTP_PASSWORD` - the credentials for logging in to the SMTP server Less commonly, you might also need to set some of the following: +- `SMTP_TLS` - set to `true` only for servers requiring implicit TLS (SMTPS on port 465); STARTTLS is used automatically by default so most servers don't need this - `SMTP_DOMAIN` - the domain name advertised to the server when connecting - `SMTP_AUTHENTICATION` - if you need an authentication method other than the default `plain` -- `SMTP_ENABLE_STARTTLS_AUTO` - if you need to disable TLS on the SMTP connection +- `SMTP_SSL_VERIFY_MODE` - set to `none` to skip certificate verification (for self-signed certs) You can find out more about all these settings in the [Rails Action Mailer documentation](https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration).