Sending forgot password link in clearance

Hello, So I’m creating my first rails app with my own idea not from a tutorial, and I’m implementing Clearance for my authentication, it’s hosted in heroku right now, and when I use the forgot password link, it gives me the ‘something went wrong error’.

What steps do I need to setup first? I can’t find it in Readme from the github repo. I already set
config.action_mailer.default_url_options = { host: 'heroku_url' }

What’s next? Thank you and sorry for the noob question.

This is likely due to your rails application SMTP settings either being incorrect or missing altogether.

I recommend using mandrillapp.com for handling your transactional emails.

If you need help setting this up refer to the sendgrid docs on Heroku. Those docs should work for 99% of the email services out there.

In the future make sure you copy / paste the Heroku logs for us to read. I’m just taking a wild shot in the dark with my above suggestion.

You can access the logs through the online dashboard or their CLI. If you don’t have the CLI I would recommend installing it… it’s the bees knees.

Checkout thoughtbot/suspenders on GitHub. It’s not perfect for every application but it helps generate a bunch of configuration files (SMTP included) that will get you up and running faster.

When I was learning rails it really helped me understand how an application is stitched together. Make sure you read through the code base / commits lest it all seem like magic.

Thanks for the reply, I haven’t set yet my smtp settings. I don’t know why i just assume it will magically send. How foolish of me. I will look on suspenders and some tutorials in setting up smtp on a rails app.

EDITED:

Here’s my development.rb file, I already set my mandrill api, but still it’s not sending, I’m testing in development but I already made the config.action_mailer.perform_deliveries = true. Help? :smile:

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  
  config.action_mailer.default_url_options = { host: 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default charset: "utf-8"

  config.action_mailer.smtp_settings = {
    address: "smtp.mandrillapp.com",
    port: "25",
    username:  "<email>",
    password: "<api key>"
  }

  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.digest = true
end

UPDATE:

Tried using gmail smtp, still cannot send forgot password link, what’s wierder is there is no error when checking the server logs. Hmmm :frowning:

If you just want to test locally I recommend using http://mailcatcher.me/

# Terminal
# Install and start the mail catcher service

gem install mailcatcher
mailcatcher

You can now view mail at http://localhost:1080/

# config/environments/development.rb
# Configure your local development environment

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

If you do not have a staging environment make sure the Mandrill settings work on production.

# config/environments/production.rb
# Note that they use port 587 and not 25

config.action_mailer.smtp_settings = {
  address: "smtp.mandrillapp.com",
  port: "587",
  username:  "<email>",
  password: "<api key>"
}

Just to nitpick, don’t put API keys / account passwords / account usernames within the code base. Use environment variables or the secrets file. If you have accidentally uploaded a public repo to GitHub (or any other source control service) consider that account compromised and change your passwords / revoke the API key.

I realize I’m resurrecting a dead thread, but I’d like to see how to implement suspenders, clearance, and sendgrid in an easy way. I’ve been racking my brain on how to set up SendGrid to work with the default clearance mailers.

Edit: As it turns out, my emails were just getting stuck as delayed jobs since I did not have any active workers. :slightly_smiling:

In these kinds of situations, I think it can be useful to have a stacktrace, which helps you see what methods were being called by what other methods before the problem happened. You can sign up for a free developer account on several of the popular error handler services (Airbrake, Rollbar, Honeybadger, etc.).

Another way to follow the trace is to tail the logs as you cause the exception. You can do this with the Parity command or by using heroku logs --tail.

Examing the stacktrace can save you from a lot of “fumbling in the dark” trying to figure out why you’re getting that confusing sorry page.