質問

I just fired up a Rails app I was building back in January which would send emails via Gmail's smtp protocol. Today I get a Net::SMTPAuthenticationError with 530-5.5.1 Authentication Required. I googled this and tried all the suggestions like re-logging into Gmail, unlocking Captcha, and changing my password. None of these worked.

Here's my development.rb code:

config.action_mailer.default_url_options = { host: "localhost:3000" }

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
} 

UPDATE

well this is strange. I changed my server to smtp.yahoo.com and I'm getting the same Rails error.

UPDATE 2 I also got a new ISP since the last time I tried this app. Could that be a problem?

役に立ちましたか?

解決 4

Well, I had to add a Windows partition next to Linux on my laptop. After re-installing, the problem went away...so I don't know what the problem was.

他のヒント

I think this could be that Google is suspicious of the website accessing your account (I had something similar recently too). Login into your gmail account and look towards the top of the page for a warning banner indicating this suspicious activity concern.

Click that warning banner at the top of the page. It should take you to a page that you can inform Gmail (by the click of a button... and maybe a word verification request) that this really was you trying to access your account. There should even be a novel little map of the location of the entity (in this case, your server) that tried to access your account.

They should have sent you an email about this. The email should look something like this:

Someone recently used your password to try to sign in to your Google Account th.good@gmail.com. This person was using an application such as an email client or mobile device.

We prevented the sign-in attempt in case this was a hijacker trying to access your account. Please review the details of the sign-in attempt: ... If this was you, and you are having trouble accessing your account, complete the troubleshooting steps listed at

http://support.google.com/mail?p=client_login

Hopefully that helps.

Just change the authentication type:

config.action_mailer.smtp_settings = {
      :address              => 'smtp.gmail.com',
      :port                 => 587,
      :domain               => 'gmail.com',
      :user_name            => ENV["GMAIL_USERNAME"],
      :password             => ENV["GMAIL_PASSWORD"]
      :authentication       => 'login',
      :enable_starttls_auto => true
}

and make sure you have values for ENV["GMAIL_USERNAME"] and ENV["GMAIL_PASSWORD"]. It should be a real gmail email-id (username) and its password. It will work fine.

Hope it helps :)

I think you are using Figaro gem. You have to setup ENV["GMAIL_USERNAME"] and ENV["GMAIL_PASSWORD"] in application.yml file. Check documentation of Figaro Gem.

Check you setting too.

config.action_mailer.smtp_settings = {
    :address              => 'smtp.gmail.com',
    :port                 => 587,
    :domain               => 'gmail.com',
    :user_name            => 'my_nick@gmail.com',
    :password             => 'secret_password',
    :authentication       => 'login',
    :enable_starttls_auto => true
  }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top