2015-09-24 26 views
0

我得到一個Net::SMTPAuthenticationError我的開發(本地)env以及當我在Heroku上主機,當我嘗試從我的rails應用程序發送郵件應用程序。郵件與Gmail給網:: SMTPAuthenticationError:與雙因素身份驗證禁用

這是在發送第一對電子郵件之後開始的(2封郵件是特定的)。

迄今爲止的所有研究都讓我認爲這應該可能是由於gmail帳戶上啓用了2-factor auth,但是當我檢查帳戶時,2-factor autt未啓用。下面

screenshot of the 2-factor auth setting on my account

是我的SMTP設置都在config/development.rbconfig/production.rb

config.action_mailer.delivery_method = :smtp 
    # SMTP settings for gmail 
    config.action_mailer.smtp_settings = { 
     :address    => "smtp.gmail.com", 
     :port     => 587, 
     :user_name   => Rails.configuration.gmail_address, 
     :password    => Rails.configuration.gmail_password, 
     :authentication  => "plain", 
     :enable_starttls_auto => true 
    } 

我的郵件設置,如下圖所示:

class StackoMailer < ActionMailer::Base 

    def success_mail 
     @my_email = Rails.configuration.gmail_address 
     mail(
     from: '[email protected]', 
     to: @my_email, 
     subject: 'Fuck Yeah! Visited successfully...' 
    ) 
    end 
end 

在調用PushWatir::StackoMailer.success_mail.deliver_now!,我得到以下錯誤:

2.2.1 :001 > PushWatir::StackoMailer.success_mail.deliver_now! 
Net::SMTPAuthenticationError: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbv8i 

    from /Users/andela/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/smtp.rb:976:in `check_auth_response' 
    from /Users/andela/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/smtp.rb:740:in `auth_plain' 
    from /Users/andela/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/smtp.rb:732:in `authenticate' 
    from /Users/andela/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/smtp.rb:567:in `do_start' 
    from /Users/andela/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/smtp.rb:520:in `start' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/mail-2.6.3/lib/mail/message.rb:252:in `deliver!' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/actionmailer-4.2.4/lib/action_mailer/message_delivery.rb:77:in `deliver_now!' 
    from (irb):1 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
    from /Users/andela/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>' 
    from bin/rails:8:in `require' 
    from bin/rails:8:in `<main>' 
2.2.1 :002 > 

什麼可能導致這種情況?

我該如何做這項工作?非常感謝您的回覆

+0

也許看看[這個答案](http://stackoverflow.com/a/25872863/199712)和它的第二個評論?此外,我可能會暫時嘗試對Gmail的信譽進行硬編碼,以確保它們符合您的想法。 –

回答

1

對我而言,解決方案之一就是允許我的Google帳戶使用「安全性較低的應用」。

步驟做到這一點如下: -

從您的谷歌帳戶設置,找到「登錄&安全」 - >「允許不夠安全的應用」,啓用它。

參考 - https://support.google.com/accounts/answer/6010255

相關問題