Ruby on Rails: How to Configure the Devise Mailer?

Jorge do Carmo picture Jorge do Carmo · Feb 17, 2017 · Viewed 12.2k times · Source

I have made an application on Ruby on Rails. I'm using Devise and I need to use the recoverable password feature. I found these configurations on development.rb:

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 = false
  config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 2525,
    domain: "gmail.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: "MY_EMAIL",
    password: "MY_PASS"
  }

When I test it, it looks okay, It doesn't throw any exception on the application, but the email never comes. Please, how can I configure this?

Answer

Pedro Nascimento picture Pedro Nascimento · Feb 17, 2017

For using locally, I recommend using something like letter_opener.

For deploying the app I'd recommend using a service like Sendgrid, it has a free tier that is good enough for small apps.

If you insist on using GMail for e-mails, try using TLS:

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