Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::SMTPAuthenticationError when sending email from Rails app (on staging environment)

I am sending email from my Rails application. It works well on development environment, but fails on staging. I get the following error:

Net::SMTPAuthenticationError (534-5.7.14 <https://accounts.google.com/ContinueSignIn?plt=AKgnsbtdF0yjrQccTO2D_6)

Note, that my I don't have a domain name for my staging.

Here are my settings in staging.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "my.ip.addr.here:80" }
config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => 'my.ip.addr.here:80'
      :user_name => "[email protected]",
      :password => "my_email_password",
      :authentication => 'login'
}

Please, help.

Edit.

After adding :tls => true option I get

OpenSSL::SSL::SSLError (Unrecognized SSL message, plaintext connection?)

And then I changed port to 25 and now I get this (with 30 seconds delay):

Timeout::Error (execution expired)
like image 810
eagor Avatar asked Aug 08 '13 11:08

eagor


2 Answers

I had the same problem: emails were sent from development, but not from production (where I was getting Net::SMTPAuthenticationError). This drove me to conclusion that the problem was not with my app's configuration, but with Google.

Reason: Google was blocking access from unknown location (app in production)

Solution: Go to http://www.google.com/accounts/DisplayUnlockCaptcha and click continue (this will grant access for 10 minutes for registering new apps). After this my app in production started sending emails ;)

like image 167
Gee-Bee Avatar answered Nov 18 '22 08:11

Gee-Bee


Solved! I simply changed password for my gmail account and somehow errors disappeared.

After dozen of changes, the final settings I ended up with are:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "my.ip.addr.here" }
config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => 'my.ip.addr.here:80',
      :user_name => "[email protected]",
      :password => "my_email_password",
      :authentication => :plain,
      :enable_starttls_auto => true
}
like image 27
eagor Avatar answered Nov 18 '22 07:11

eagor