LoginSignup
1
0

More than 5 years have passed since last update.

devise+gmailで認証メールを送る設定でエラーが出る対応策

Posted at

deviseでデフォルトではgmailに送れないのですが、下記の設定で
送れるようになります。

config/environment/development.rb
config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "smtp.gmail.com",
    :user_name => '[myaccount@gmail.com]',
    :password => '[app_password]',
    :enable_starttls_auto => true,
    :authentication => "plain",
    }

この場合、試用のためにuser_namepasswordに生の文字列を直接入れてましてエラーがでました。

Net::SMTPAuthenticationError in Devise::RegistrationsController#create
534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgn

原因はpasswordが違うということなんですが、googleのアプリパスワードは間違っていません。

対応策:

環境変数に換えて打ち直すと実行できた。

:user_name => Rails.application.secrets.google_address,
:password => Rails.application.secrets.google_password,

おそらく生パスワードをgoogle側で拒否しているように思われる(詳しく調べてない、調べられない)。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0