0

I am developing a Rails app on Cloud9, I am trying to do something pretty simple, which is to get the Devise confirmation emails to work. For some reason, they are not being sent.

I'm using SendGrid for email functionality. I know that SendGrid is working correctly, because I can make a trivial ActionMailer that sends a test email. But for some reason, the Devise confirmation emails are not being sent. I can see that it is making a call on ActionMailer::Base.mail method, but the mail is never delivered.

I have no idea how to debug this.

Just to prevent suggestions to check stuff that is already working:

  • The user options include :confirmable
  • I am setting config.action_mailer.perform_deliveries = true
  • I have the following lines in config/initializers/setup_mail.rb

Code:

if Rails.env.development? || Rails.env.production?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  address:        'smtp.sendgrid.net',
  port:           '2525',
  authentication: :plain,
  user_name:      ENV['SENDGRID_USERNAME'],
  password:       ENV['SENDGRID_PASSWORD'],
  domain:          "sendgrid.com",
  enable_starttls_auto: true
}
Daryl McCullough
  • 303
  • 5
  • 20
  • In trying to debug what was going on, I tried calling `mail` from within the rails console. What I found was that directly calling `ActionMailer::Base.mail` never results in the mail being delivered, but if I call it indirectly through a subclass of `ActionMailer`, it works. Why in the world wouldn't the base class work? – Daryl McCullough May 01 '17 at 00:27
  • Why would it work? ActionMailer::Base is made to be subclassed. – max May 01 '17 at 00:34
  • But the subclass doesn't seem to add much functionality: `class ApplicationMailer < ActionMailer::Base default from: "from@example.com" layout 'mailer' end` – Daryl McCullough May 01 '17 at 00:42
  • 1
    Shouldn't the port be an integer compared to a string? – jdgray May 01 '17 at 00:42
  • check the `config.action_mailer.raise_delivery_errors = false` line and set that to true so you can see the errors if any – jvnill May 01 '17 at 00:43

1 Answers1

0

I'm guessing that my solution is not the intended solution, but it works (although I'm not sure why).

In the file config/initializers/setup_mail.rb, I added the following two lines:

  1. ActionMailer::Base.layout 'mailer'
  2. ActionMailer::Base.default from: "from@example.com"

These are probably things that should be specified in some configuration file for Devise, but I didn't see any instructions for doing so.

[Edit] It is only line 2 that is important. It doesn't matter that the "from" address is a bogus email address, but if it is missing, the email does not get delivered.

Daryl McCullough
  • 303
  • 5
  • 20