Openstreetmap-website: Expose smtp config

Created on 28 Mar 2020  路  6Comments  路  Source: openstreetmap/openstreetmap-website

I want to use an external mail service, such as mailgun, to send emails. Is it possible to configure the openstreetmap server to use that instead of a mail server running on localhost?

support

Most helpful comment

Well that is the purpose of the file

I think it would be better if settings were managed through the settings system, rather than having to write ruby code like this. The production.rb file should be used for stuff that's likely to apply to all production deployements, but e.g. smtp passwords are going to differ between all deployments and so aren't really compatible with that file.

So I'm glad that @kgreenek found a solution, but I think that we can make life easier by exposing settings like these via the settings.yml files.

All 6 comments

I have no idea - the ActionMailer documentation is the place to start.

I mean if that service offers an SMTP endpoint then I'm sure it's just a question of setting the appropriate ActionMailer configuration options.

See https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration for an ActionMail configuration guide.

Thank you for the help! I got it to work with the following lines in my Dockerfile:

echo "
Rails.application.configure do
  # Override the default settings loaded in config/initializers/action_mailer.rb.
  config.after_initialize do
    ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.smtp_settings = {
      :address => 'smtp.mailgun.org',
      :port => 587,
      :domain => 'mywebsite.com',
      :user_name => '${OSM_MAILGUN_USERNAME}',
      :password => '${OSM_MAILGUN_PASSWORD}',
      :authentication => 'plain',
      :enable_starttls_auto => true,
    }
  end
end" >> "config/environments/production.rb"

It feels a bit weird to patch the production.rb file, but I couldn't figure out a better way.

Well that is the purpose of the file, although I generally prefer to drop something into config/initializers instead.

Well that is the purpose of the file

I think it would be better if settings were managed through the settings system, rather than having to write ruby code like this. The production.rb file should be used for stuff that's likely to apply to all production deployements, but e.g. smtp passwords are going to differ between all deployments and so aren't really compatible with that file.

So I'm glad that @kgreenek found a solution, but I think that we can make life easier by exposing settings like these via the settings.yml files.

Was this page helpful?
0 / 5 - 0 ratings