Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails : Send email via Gmail in production

I want to send email via my gmail account in PRODUCTION. It works great in local host.

In my environment.rb I have :

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
 :address             => "smtp.gmail.com",
 :port                => 587,
 :domain              => "myhost.com",
 :authentication      => "plain",
 :user_name           => "[email protected]",
 :password            => "mypassword",
 :enable_starttls_auto => true

}

And in my production.rb file :

config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'gmail.com' }

But it doesn't work and I have that error :

Errno::ECONNREFUSED (Connection refused - connect(2)):

Any ideas ? My app is deployed on Heroku. For the host what do I have to put ?

Thanks !

like image 629
Maxxx Avatar asked Apr 24 '12 01:04

Maxxx


1 Answers

Host should be www.yourapp.com. My settings for gmail on Heroku look like this, and they work:

config.action_mailer.default_url_options = { :host => 'www.myapp.com' }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "gmail.com",
    :authentication => :login,
    :user_name => "[email protected]",
    :password => "mypassword"
}
like image 102
Andrew Avatar answered Oct 13 '22 20:10

Andrew