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

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 ;)


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
}

This solution is working for me:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host:'localhost', port: '3000' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"
  config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => 'localhost:3000',
      :user_name => "[email protected]",
      :password => "password",
      :authentication => :plain,
      :enable_starttls_auto => true
  }

It's true that Google will block your sign-in attempt but You can change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards.