LoginSignup
16
17

More than 1 year has passed since last update.

Gmail 経由での SMTP メール送信が出来ない時の解決法 (ユーザー名とパスワードは合っているのに。。)

Last updated at Posted at 2015-10-22

問題

  • Google側で2段階認証をオンにした。
  • アプリケーション用のパスワードを発行した。

だがしかし。

メールアドレスもパスワードも合っているはずなのに。
Username and Password not accepted ( ユーザー名とパスワードが許可されていない ) と言われて失敗する。

Ruby on Rails の場合。

UserMailer.registration_confirmation.deliver_now

結果:

Net::SMTPAuthenticationError: 535-5.7.8 Username and Password not accepted. Learn more at
from /Users/yinaura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/net/smtp.rb:976:in `check_auth_response'

解決

いつの間にか。
Gmail アドレス以外からは、SMTP 送信ができないようになっていた。( 2014年8月から )

=> 別のアドレスから送信する場合は、Gmail の SMTP サーバーを選択できなくなりました

結論。アカウント を Gmail のものに変えたら成功した。


-   :user_name => 'example@company.com', # gmail アドレスじゃないので使えない
+   :user_name => 'example@gmail.com', # gmail アドレスなので使える

以下は Ruby on Rails の場合の設定だ。

config/environment/development.rb
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => 'smtp.gmail.com',
    :port => 587,
    :domain => 'example.com',
    :user_name => 'example@gmail.com',
    :password => 'dlapwoeifkbmzksl', # Googleが発行する、12桁のアプリケーションパスワード
    :authentication => :login,
    :enable_starttls_auto => true
  }

参照

次の記事を参考にした。

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

16
17
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
16
17