Net::SMTPAuthenticationError when sending email fr

2019-01-03 07:57发布

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 => "my_email_name@gmail.com",
      :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)

11条回答
看我几分像从前
2楼-- · 2019-01-03 08:18

I had the same problem and after some trial and errors, have come to this resolution which is an option to be enabled in google:

Click https://www.google.com/settings/u/0/security/lesssecureapps

Enable 'Access for less secure apps' here by logging in with the email address you have provided in smtp configuration.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-03 08:27

I also faced the problem, and after some research in Gmail setting, I found the solution:

  1. In gmail, go to settings.

  2. Select "Forwarding and POP/IMAP" tab.

  3. In the IMAP access section, select "Enable IMAP".

查看更多
不美不萌又怎样
4楼-- · 2019-01-03 08:28

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 => "xyz@gmail.com",
      :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.

查看更多
【Aperson】
5楼-- · 2019-01-03 08:28

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 => "my_email_name@gmail.com",
      :password => "my_email_password",
      :authentication => :plain,
      :enable_starttls_auto => true
}
查看更多
劫难
6楼-- · 2019-01-03 08:28

The accepted answer seems very old, I don't know if at that time the followin (better) solution was existing:

Now, sending emails works perfectly!

查看更多
做个烂人
7楼-- · 2019-01-03 08:34

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

查看更多
登录 后发表回答