banditKing
banditKing

Reputation: 9579

Sending an email from Rails app- works in development, not in production on Heroku

I am trying to use the gem Active Admin to send emails to users that I sign up so that they can create a password.

This entails a process of inserting the following code on the config/environments/development.rb

 #Added per active admin install instructions
 config.action_mailer.default_url_options = { :host => 'localhost:3000' }

 #These settings are for the sending out email for active admin and consequently the devise mailer
 ActionMailer::Base.delivery_method = :smtp
 ActionMailer::Base.perform_deliveries = true
 ActionMailer::Base.raise_delivery_errors = true
 ActionMailer::Base.smtp_settings = 
 {

   :address            => 'smtp.gmail.com',
   :port               => 587,
   :domain             => 'gmail.com', #you can also use google.com
   :authentication     => :plain,
   :user_name          => '[email protected]',
   :password           => 'XXXX'
 }

THis works no problems

For deploying to the production site on Heroku. I inserted the following code into the config/environments/production.rb

 #Added per active admin install instructions
 config.action_mailer.default_url_options = { :host => 'http://XXXX.herokuapp.com/' }

 #These settings are for the sending out email for active admin and consequently the devise mailer
 ActionMailer::Base.delivery_method = :smtp
 ActionMailer::Base.perform_deliveries = true
 ActionMailer::Base.raise_delivery_errors = true
 ActionMailer::Base.smtp_settings = 
 {

   :address            => 'smtp.gmail.com',
   :port               => 587,
   :domain             => 'gmail.com', #you can also use google.com
   :authentication     => :plain,
   :user_name          => '[email protected]',
   :password           => 'XXX'
 }

But now the emails donot get sent. Instead I see a "We're sorry soemthing went wrong" message in the browser and the logs say the following lines

2012-08-17T17:39:34+00:00 app[web.1]:     cache: [GET /admin/admin_users/new] miss

2012-08-17T17:39:34+00:00 app[web.1]: Started POST "/admin/admin_users" for   96.49.201.234 at 2012-08-17 17:39:34 +0000
2012-08-17T17:39:35+00:00 app[web.1]: Net::SMTPAuthenticationError (535-5.7.1 Please log   in with your web browser and then try again. Learn more at

2012-08-17T17:39:35+00:00 app[web.1]: ):
2012-08-17T17:39:35+00:00 app[web.1]:   app/models/admin_user.rb:35:in `block in <class:AdminUser>'

2012-08-17T17:39:35+00:00 app[web.1]: cache: [POST /admin/admin_users] invalidate, pass

Where should I go from here? Can someone please give me a hand

Upvotes: 1

Views: 2555

Answers (4)

Sai Ram Reddy
Sai Ram Reddy

Reputation: 1089

http://www.google.com/accounts/DisplayUnlockCaptcha click on this and give access to it. The next time it will work

Upvotes: 0

Blue Smith
Blue Smith

Reputation: 8820

Here is a useful help from Gmail: http://support.google.com/mail/bin/answer.py?hl=en&answer=14257&p=client_login.

The problem is Gmail prevents suspicious sign-in attempt that may be robot. We need to grant permission to the app so that it can use Google Account to send email.

Upvotes: 1

varunvlalan
varunvlalan

Reputation: 950

Try following code:

 ActionMailer::Base.smtp_settings = 
 {

   :address              => 'smtp.gmail.com',
   :port                 => 587,
   :domain               => 'gmail.com', #you can also use google.com
   :authentication       => 'plain',
   :user_name            => '[email protected]',
   :password             => 'XXX',
   :enable_starttls_auto => true
 }

Changes made:
1. :authentication => :action to :authentication => 'plain'
2. added :enable_starttls_auto => true , as commented by janders223 above.

Upvotes: 0

janders223
janders223

Reputation: 3153

Gmail requires SSL connections to their mail servers. Try adding this to your SMTP settings:

:enable_starttls_auto => true

Upvotes: 0

Related Questions