How do I set up email confirmation with Devise?

前端 未结 3 1353
我在风中等你
我在风中等你 2020-11-28 17:12

Is there a tutorial out there that explains how to set up Devise\'s signup confirmation email from scratch (in both development and production), i.e. if you don\'t have Acti

相关标签:
3条回答
  • 2020-11-28 17:56

    1. Make sure you include confirmable in Model.devise call

    class User < ActiveRecord::Base
      devise :database_authenticatable, :confirmable ...
    end
    

    2. Make sure you add confirmable to the user migration

    create_table :users do |t|
      t.database_authenticatable
      t.confirmable
      ...
    end
    

    If you're using devise 2.0+ this fails because devise no longer provides migration helpers, and so t.confirmable raises an error. Instead, copy the block labeled "Confirmable" from their migration guide.

    3. Generate the devise views, with either of the following commands,so you can override the devise mailer views:

    rails generate devise:views # global
    rails generate devise:views users # scoped
    

    You can now override the mailer views in devise/mailer/confirmation_instructions.html.erb or users/mailer/confirmation_instructions.html.erb depending on your setup

    4. For development environment add the following config lines in /config/environments/development.rb

    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}
    

    5. For production environment in /config/environments/production.rb you may use something similar to the following (supposing you have a SMTP server on localhost:25):

    config.action_mailer.default_url_options = {:host => 'yourdomain.com'}
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :address => "127.0.0.1",
      :port    => 25,
      :domain  => 'yourdomain.com'
    }
    

    6 To test the setup in development install the mailcatcher gem, that you will use as a SMTP server in development, catching all incoming mails and displaying them on http://localhost:1080/:

    gem install mailcatcher
    

    Once installed start the mailcatcher server with the command:

    mailcatcher
    

    A toy SMTP server will be running on port 1025 catching emails and displaing them on HTTP port 1080.

    You can now create an account and see the confirmations.

    0 讨论(0)
  • 2020-11-28 17:59

    Have you looked at the ActionMailer Rails Guide?

    0 讨论(0)
  • 2020-11-28 18:10

    I believe you should edit it once again... port no. should be in quotes .. Like this :-

    :port => "587",
    

    I faced a problem in rails 3.2.0/ruby 1.9.2

    0 讨论(0)
提交回复
热议问题