Skip to content

Conversation

@harisadam
Copy link
Contributor

@harisadam harisadam commented Dec 4, 2025

Looks like Fizzy currently defaults to Sendmail, this update enables developers to switch to SMTP when needed via environment variables.

@arnsteinsm
Copy link

Hey! Just wanted to add a quick note: before I found this PR, I ended up doing almost the same SMTP setup in my own fork so I could run Fizzy self-hosted.

I’ve tested the env-based SMTP approach on Coolify (ARM server) using Mailgun, and it works very well.

Thanks for putting it together!


config.action_mailer.perform_caching = false

config.action_mailer.delivery_method = ENV.fetch("MAILER_DELIVERY_METHOD", "sendmail").to_sym
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting to sendmail might be surprising, since it's not the usual Rails default.

What do you think about defaulting to smtp instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats my preference, I think most people use smtp as well, change has been added

Copy link
Collaborator

@kevinmcconnell kevinmcconnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thanks @harisadam!

@kevinmcconnell
Copy link
Collaborator

kevinmcconnell commented Dec 5, 2025

Note that we're currently setting specific SMTP settings in fizzy-saas, which would be overwritten by the settings provided here.

So before we can merge this, we need to resolve that situation. Either fizzy-sass needs to use the same env vars, or maybe invert the order that these environment files get applied so that fizzy-sass can take priority.

cc @jorgemanrubia

@harisadam
Copy link
Contributor Author

@kevinmcconnell This might be a better approach and make this PR irrelevant:
#1958

@kevinmcconnell
Copy link
Collaborator

@harisadam how about we make this all conditional on whether MAILER_DELIVERY_METHOD is set? If it's not set, the default is to leave the config alone. That would make it compatible with our (and other) engines, but still provide a simple way to configure the settings via env var.

@eval
Copy link

eval commented Dec 8, 2025

Maybe allow for 1 env-var SMTP_URL instead of 8?
Shameless self-promotion: I created uri-smtp that extends URI to understand uri's using smtp(s) protocols:

+  config.action_mailer.smtp_settings = URI(ENV.fetch("SMTP_URL")).to_h(format: :am)

-  config.action_mailer.smtp_settings = {
-    address: ENV.fetch("SMTP_ADDRESS", "localhost"),
-    port: ENV.fetch("SMTP_PORT", "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"
-  }

The SMTP_URL can now double as MAILER_DELIVERY_METHOD - when it's there, use SMTP otherwise use a fallback.

Besides being more convenient to have 1 var, it also:

  • ...has proper defaults.
    e.g. starttls: :always, but not for local development (against e.g. mailcatcher), ports for smtps://.. vs smtp://... etc.
  • ...works around a bug in mail-gem v2.8.1 that when setting tls: false, starttls will be ignored
    Probably the reason the rails sample config doesn't contain the tls-setting(?)
  • ...provides a consistent config
    e.g. tls: true ánd starttls: true (which makes no sense): URI("smtps://user:pass@gmail.com?starttls=true").starttls #=> false. URI("smtp://gmail.com?authentication=plain").auth #=> nil (prevents net-smtp from raising because there's no authinfo).
    But to start: weird configurations in URI-form are more easily spotted because they look weird.

@kevinmcconnell
Copy link
Collaborator

@harisadam fyi I've rebased these changes to resolve the conflicts, and I've made the setup conditional on whether SMTP_ADDRESS is set.

@harisadam
Copy link
Contributor Author

🚀 @kevinmcconnell thanks looks good to me - sorry I’ve been swamped with work

- If `SMTP_ADDRESS` is set, configure Action Mailer to use it, along
  with additional optional SMTP-related settings.
- Otherwise, don't set config (for compatibility with engines like
  fizzy-saas).
- Remove sendmail env setup, since by default there is no sendmail in
  the container, and custom deployment can use whatever config the want
  directly. If we end up needing this, we can bring it back via its
  own env.
@kevinmcconnell
Copy link
Collaborator

@eval the URL config is an interesting idea, but I think the individual params will probably be more familiar to folks setting up a Fizzy instance. So we'll stick with those for now, and see how that goes. Thanks for the suggestion though.

@kevinmcconnell
Copy link
Collaborator

@harisadam no worries at all. Thanks for getting this started! 🙏

@kevinmcconnell kevinmcconnell merged commit 0430ce0 into basecamp:main Dec 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants