18
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Googleで2段階認証を使っているときにRailsのActionMailerでGmailを使う方法

Last updated at Posted at 2013-01-16

問題

RailsでActionMailerを使って、Gmailでメールを送信しようとすると、
Application-specific password required
なるエラーが発生しました。

調べたところ、
Stackoverflowでも同様の質問がありました。
http://stackoverflow.com/questions/11007061/error-when-sending-email-confirmation-using-actionmailer-on-ror

解決方法

/config/environments/development.rb
  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "gmail.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["GMAIL_USERNAME"],
    # 消す password: ENV["GMAIL_PASSWORD"],
    password: "ここに、アプリケーション固有のパスワードを入れる"
  }

というように、アプリケーション固有のパスワードを設定すれば、問題なくメール送信できました。通常のログインに使うパスワードは不要です。

18
21
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
18
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?