1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00
Maybe/app/mailers/application_mailer.rb
Thibaut Gorioux 6fdb8e8d69
Allow a self-hosted user to configure their SMTP settings directly from within the UI (#682)
* Add setting fields to model

* Allow to configure SMTP settings

* Normalize locales

* Cleanup locales

* Remove 'coming soon'

* fix test

* Reset credentials

* Reset development config

* Check smtp spelling

* Use post instead of get method

* TLS ENV variable is more descriptive

* Rework application mailer

* Follow rails convention for mailer action params

* Reset schema.rb to main

* Test WIP

* Add test for controller and mailer

* Move tests from controller to model

* Custom error message if settings are not all present

* Comment smtp config in development env

* Add default tls enabled value

* Rubocop

* Fix controller test

* Reset credentials

* Normalize locales

* Test

* fix test

* Fix application mailer test that fails randomly

* Error flash message instead of notice

* Rework application mailer tests
2024-04-29 16:44:24 -04:00

16 lines
632 B
Ruby

class ApplicationMailer < ActionMailer::Base
layout "mailer"
after_action :set_self_host_settings, if: -> { ENV["SELF_HOSTING_ENABLED"] == "true" }
private
def set_self_host_settings
mail.from = Setting.email_sender
mail.delivery_method.settings.merge!({ address: Setting.smtp_host,
port: Setting.smtp_port,
user_name: Setting.smtp_username,
password: Setting.smtp_password,
tls: ENV.fetch("SMTP_TLS_ENABLED", "true") == "true" })
end
end