Ruby on Rails: How to Configure the Devise Mailer?
Asked Answered
L

2

7

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?

Landgrave answered 17/2, 2017 at 16:59 Comment(3)
Do you have a google apps account for gmail? If not, sending email like this will end up in the spam folder.Spicer
You have to enable google account so it can able to send mailAerial
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.Freightage
H
11

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
}
Hymanhymen answered 17/2, 2017 at 17:17 Comment(2)
Yes, I do use my email and my pass on those spots, and it doesn't work at all.Landgrave
I've updated the answer with a way of using GMail, hope it helps.Hymanhymen
C
4

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

Corkwood answered 22/4, 2021 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.