Configuring Gmail SMTP with Actionmailer
Just a couple of reminders for myself, in case I spend wasted time trying to get gmail smtp working on actionmailer again.
To get your ActionMailer configured for gmail:
# in config/environments.rb
# add the following lines AFTER your Rails::Initializer.run block
email_settings = YAML::load(File.open("#{RAILS_ROOT}/config/email.yml"))
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = email_settings[RAILS_ENV] unless email_settings[RAILS_ENV].nil?
in config/email.yml (if its not there, create it)
add the following for each rails environment
development:
:enable_starttls_auto: true
:address: smtp.gmail.com
:port: 587
:authentication: :plain
:user_name: <[email protected]>
:password: <password>
:domain: gmail.com
remember the extra ‘:’ before the yaml key. This is what wasted my time
And magic.There’s no need to install any new smtp/tls libraries as there’s already built in support for tls authentication within ActionMailer. Just make sure to set ’enable_starttls_auto’ to true.