ActionMailerとGmailと2段階認証
ActionMailerでGmailからメールを送信しようとしていなのですが、うまくいきません。
設定は下記の通りで、ググるとみんなこれで送信できております。
config.action_mailer.smtp_settings = { :enable_starttls_auto => true, :domain => 'gmail.com', :address => 'smtp.gmail.com', :port => 587, :authentication => :plain :user_name => 'username', :password => 'password', }
エラーメッセージはこんな感じ。
Completed 500 Internal Server Error in 2365ms Net::SMTPAuthenticationError (535-5.7.1 Username and Password not accepted. Learn more at
さらにググっていたら、Googleで2段階認証を設定している場合の方法を書いているページを発見。
私の環境では "Application-specific password required" というエラーは出ていないようなのですが、2段階認証は有効にしているので試してみます。
Google Accountからアプリケーション固有のパスワードを取得してきて、もう1個:passwordを設定します。
こんな感じです。
config.action_mailer.smtp_settings = { :enable_starttls_auto => true, :domain => 'gmail.com', :address => 'smtp.gmail.com', :port => 587, :authentication => :plain :user_name => 'username', :password => 'password', :password => 'アプリケーション固有のパスワード', }
成功しました。
ではでは。