Rails 3 SMTP configuration requires symboloc keys

18 Aug 2012

I don't know whether to laugh or cry…

If you assign the SMTP setting like this:

ActionMailer::Base.smtp_settings = { "address" => "smtp.gmail.com", "port" => "587", "authentication" => "plain", "user_name" => "user", "password" => "pass", "enable_starttls_auto" => true }

You will get `Connection refused - connect(2). Of course, this is because the configs are not read at all.

But if you do this:

ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => "587", :authentication => "plain", :user_name => "user", :password => "pass", :enable_starttls_auto => true }

It works…

Therefore, convert all the keys to symbols with this:

my_hash = my_hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}

Give it a kudos