LoginSignup
3
0

More than 3 years have passed since last update.

devise メール認証

Posted at

はじめに

deviseを使ったメール認証の設定について書いていきます。

設定ファイルの編集

送信者のメールアドレス指定

config/initializers/devise.rb
Devise.setup do |config|
省略..

config.mailer_sender = "info~@~.com"
end

config.mailer_senderはdevise.rbにデフォルトで設定されているのでこちらを適宜変更。

変更なしの場合、

config.mailer_sender = 'from@example.com'

が設定されている。

SMTP環境の設定

メールを送信するには追加でSMTPの設定が必要となる。

Gmailを使用する場合はメールアドレスとパスワードも必要。

以下のようにdevelopment.rbを編集する。

config/environments/development.rb
Rails.application.configure do
  # default url
  config.action_mailer.default_url_options = {  host: 'localhost', port: 3000 }
  # mail setting
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :user_name => "Gメールアドレス",
    :password => "Gメールパスワード",
    :authentication => :plain,
    :enable_starttls_auto => true
  }
end

2段階認証をかけている場合、以下参照
https://qiita.com/cigalecigales/items/f4274088f20832252374

参考

https://qiita.com/cigalecigales/items/f4274088f20832252374
https://qiita.com/shizuma/items/c8c2e71af8c1dcf3d1c2
https://easyramble.com/devise-setup-config-mailer-sender.html

3
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
3
0