简体   繁体   中英

Rails devise does not send confirmation email but requires

I set up Devise and am able to create a profile. When I create the profiles and try to log in, I get an error message that I have not confirmed my account,

I never got the email which I am supposed to confirm my own account. Did I go wrong in selecting such an option, or not enabling Devise to email me?

Here is the migration I used to make it:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.confirmable
      t.encryptable
      t.column "first_name", :string  
      t.column "last_name", :string
      t.column "organization_name", :string

      t.timestamps
    end

    add_index :users, :email,                :unique => true
  end

  def self.down
    drop_table :users
  end
end

In development mode, you have to add this line to config/environments/development.rb

config.action_mailer.default_url_options = {:host => 'localhost:3000' }

Then, check your server logs to see the mail. You should find something like that:

Rendered devise/mailer/confirmation_instructions.html.erb (19.5ms)

Sent mail to example@mail.com (21951ms)

Date: Thu, 26 May 2011 12:56:55 +0200

From: sender@mail.com

Reply-To: sender@mail.com

To: example@mail.com

Message-ID: <4dde31f7944bd_5ac277e0e4785c6@L-Portable.mail>

Subject: Confirmation instructions

Mime-Version: 1.0

Content-Type: text/html;

charset=UTF-8

Content-Transfer-Encoding: 7bit
<p>Welcome example@mail.com!</p>
<p>You can confirm your account through the link below:</p>
<p><a href="http://localhost:3000/users/confirmation?confirmation_token=Hi0tyRQU8cCFpAbatYFf">Confirm my account</a></p>

You also need to put this line in config/initializers/devise.rb

config.mailer_sender = "sender@mail.com"

If you REALLY don't have this mail in your logs, you can still validate your account by taking the value of confirmation_token in your DB and go to this link

http://localhost:3000/users/confirmation?confirmation_token= #PUT_YOUR_TOKEN_HERE

And that should do the trick.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM