6

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?

Jorge do Carmo
  • 65
  • 1
  • 1
  • 7
  • Do you have a google apps account for gmail? If not, sending email like this will end up in the spam folder. – Eyeslandic Feb 17 '17 at 17:01
  • You have to enable google account so it can able to send mail – uzaif Feb 17 '17 at 17:13
  • I had the same problem of failing to receive email from Devise in development using Google Mail. I use SendGrid instead and I do receive the emails. If you don't really need to get the actual email. You can just look at Rails Server log to see the email. – tkhuynh Feb 17 '17 at 22:34

2 Answers2

10

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: "jorge@example.org",
  password: "your_password",
  authentication: 'plain',
  enable_starttls_auto: true
}
Pedro Nascimento
  • 13,136
  • 4
  • 36
  • 64
2

Stumbled across this older question and figured I would provide a current answer here. If you're trying to use a Gmail account with your Devise Rails app for any reason (prototyping, developing, etc - no judgements), Pedro's answer is spot on with 1 exception. The password for the SMTP server is not your user password. This may have been ok in the past, but now you have to generate a new app password separate from your user password.

Directions can be found on Google's Support site here: https://support.google.com/accounts/answer/185833?hl=en

adconk
  • 31
  • 2