LoginSignup
8
8

More than 5 years have passed since last update.

DeviseでGmail経由でメールを送信する方法

Posted at

開発環境(Vagrant)のRailsアプリから手軽にメール送信を確認するため、Gmail経由でメールを送信する。
なお、Gmailは送信数に制限があるようなので注意が必要。

動作環境

  • Ruby on Rails 4.1.1
  • Devise 3.3.0

設定

default_url_optionsuser_namepasswordは適宜変更する。
設定後はサーバの再起動を忘れない。

config/environments/development.rb
Rails.application.configure do

  # ...

  config.action_mailer.default_url_options = { host: '192.168.33.10', port: 3000 }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
    address: 'smtp.gmail.com',
    port: 587,
    user_name: 'username@gmail.com',
    password: 'password',
    authentication: :plain,
    enable_starttls_auto: true
  }
end

参考

8
8
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
8
8