Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
Created March 31, 2014 03:39
Show Gist options
  • Save joshmcarthur/9884826 to your computer and use it in GitHub Desktop.
Save joshmcarthur/9884826 to your computer and use it in GitHub Desktop.
Load email settings from a YAML configuration file
# config/email.yml
---
test:
:delivery_method: :test
:url_host: 'localhost:3000'
development:
:delivery_method: :smtp
:host: "localhost:1025"
production:
:delivery_method: :smtp
:address: 'localhost'
:port: 25
# config/initializers/mail_settings.rb
email_settings = YAML.load_file("#{Rails.root.to_s}/config/email.yml")[Rails.env.to_s]
Rails.application.config.action_mailer.default_url_options = {
host: email_settings.delete(:url_host) || "localhost:3000"
}
Rails.application.config.action_mailer.delivery_method = email_settings.delete(:delivery_method)
Rails.application.config.action_mailer.smtp_settings = email_settings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment