David R Newman

Email Configs

So far I have had to use two different configs for sending email depending on where my server is located, i.e. if it is on the same domain as the smtp server of not.

Same Domain as SMTP Server

production:
  server: smtp
  port: 25
  domain: localhost.localdomain

Differnt Domain to SMTP Server

production:
  server: smtp.[smtp server domain]
  port: 25
  domain: [smtp server domain]
  authentication: login
  username: [my username]
  password: [my password]

Defining Settings in environment.rb File

Instead of defining the email settings in a email.yml the settings can be defined in the environment.rb file as follows;

Same Domain as SMTP Server

ActionMailer::Base.smtp_settings = {
  :adddress => "smtp",
  :port => 25,
  :domain => "localhost.localdomain"
}

Differnt Domain to SMTP Server

ActionMailer::Base.smtp_settings = {
  :adddress => "smtp.[smtp server domain]",
  :port => 25,
  :domain => "[smtp server domain]",
  :authentication => :login,
  :user_name: => "[my username]",
  :password => "[my password]"
}

Be careful to node that username changes to user_name, which is often a mistake made when converting from one format to the other.

<< Back to RoR Tips Index Page

Page written by David R Newman (drn[at]ecs.soton.ac.uk). Last updated June 27 2018 14:44:07.