7
votes

I'm testing Devise authentication for Rails on my local host and want to get it to send emails for password retrieval (i.e. the "forgot your password" link). Password retrieval is built into Devise, it's just a matter of configuring it properly to get the email to send.

In initializers/devise.rb, I put

config.mailer_sender = "[email protected]" 

but when I tried to test the "forgot your password" link on Devise authentication for rails I got the error message below. If I do need to add other information for the email to actually send, what do I need to add and where??

In users model, these are the modules that are being used devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

--- error message --- Errno::ECONNREFUSED in Devise::PasswordsController#create Connection refused - connect(2) Rails.root: /Users/myname/Sites/rails3d Application Trace | Framework Trace | Full Trace Request Parameters: {"utf8"=>"✓", "authenticity_token"=>"8oO5vXqO4esl3ztn5yE7OkVxZe+Ju94jj76rbKR225I=", "user"=>{"email"=>"[email protected]"}, "commit"=>"Send me reset password instructions"} Show session dump Show env dump Response Headers

2
I ended up in the same place. this feature is really poorly documented.Arel

2 Answers

4
votes

HAve you setup your mail settings in environments/development.rb

  config.action_mailer.smtp_settings = {
     :address              => "smtp.gmail.com",
     :port                 => 587,
     :domain               => 'domain.com',
     :user_name            => '[email protected]',
     :password             => 'password',
     :authentication       => :plain,
     :enable_starttls_auto => true  }
4
votes

In addition to what TJ said above, I'd recommend looking at the MailCatcher gem for testing emails locally. I've been using it a few days now and it works great.

mailcatcher.me

Also if you want the email to be sent and not just logged make sure and enable delivery in your development.rb file as well:

  config.action_mailer.perform_deliveries = true