-
Notifications
You must be signed in to change notification settings - Fork 573
Configure email delivery in production using environment variables #1911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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/environments/production.rb
Outdated
|
|
||
| config.action_mailer.perform_caching = false | ||
|
|
||
| config.action_mailer.delivery_method = ENV.fetch("MAILER_DELIVERY_METHOD", "sendmail").to_sym |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
kevinmcconnell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thanks @harisadam!
|
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. |
|
@kevinmcconnell This might be a better approach and make this PR irrelevant: |
|
@harisadam how about we make this all conditional on whether |
|
Maybe allow for 1 env-var + 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 Besides being more convenient to have 1 var, it also:
|
|
@harisadam fyi I've rebased these changes to resolve the conflicts, and I've made the setup conditional on whether |
|
🚀 @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.
|
@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. |
|
@harisadam no worries at all. Thanks for getting this started! 🙏 |
Looks like Fizzy currently defaults to Sendmail, this update enables developers to switch to SMTP when needed via environment variables.