Dec232009

Action Mailer Configuration for Google app or Gmail

Recently I needed to setup smtp server to send mail. nothing was new, I simply used rails ActionMailer as one
should be. It should have been working, but wait; ohhhhhh snap, it was not!

It came out to be our very own google’s fault. Yes! as the email server was hosted on google app. And our google uses SSL SMTP or to be precise STARTTLS for routing emails. So here I am writing down step by step, what worked for me.

1. Create #{RAILS_ROOT}/config/mailer_settings.yml with following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
development:
	enable_starttls_auto:  true
	address: "smtp.gmail.com"
	port: 587
	domain:  'http://'
	authentication: plain
	user_name: "user@domain_name"
	password:  your-password
 
production:
	enable_starttls_auto:  true
	address: "smtp.gmail.com"
	port: 587
	domain:  'http://'
	authentication: plain
	user_name: "user@domain_name"
	password: your-password

Note: you can use enable_starttls_auto directly if your rails version > 2.2 and ruby
version is >=1.8.7, because built-in support for starttls. If not, then also you can use it; but you first need to install this gem.

1
gem install ambethia-smtp-tls

make dependencies

1
2
#in "#{RAILS_ROOT}/config/environment.rb" write the following
config.gem "ambethia-smtp-tls", :lib => "smtp-tls", :source => "http://gems.github.com/"

2. Load mail configuration settings, if not in test environment

1
2
3
4
5
# Load mail configuration if not in test environment
if RAILS_ENV != 'test'
	email_settings = YAML::load(File.open("#{RAILS_ROOT}/config/mailer_settings.yml"))
	ActionMailer::Base.smtp_settings = email_settings[RAILS_ENV] unless email_settings[RAILS_ENV].nil?
end

:) Happy Boarding

Both comments and pings are currently closed.

No Responses

Comment RSS Trackback URL

Comments are closed.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes