jedi
jedi

Reputation: 2198

Can't send email using Gmail on Heroku

I can't get my Rails app to send emails using Gmail. I can send emails on my local development environment but I can't send it from Heroku. This is my config file.

application.rb

  config.action_mailer.smtp_settings = {
    :address        => 'smtp.gmail.com',
    :domain         => 'gmail',
    :port           => 587,
    :user_name        => ENV['GMAIL_USERNAME'],
    :password         => ENV['GMAIL_PASSWORD'],
    :authentication     => 'login',
    :enable_starttls_auto => true
  }

I have tried authentication: 'login' and 'plain' but that didn't work either. I have tried putting this config both into application.rb and production.rb and that didn't work. I've tried domain: "my_my_name_on_heroku.com" but that didn't work either. I have also tried 'mail.google.com' but no luck either. I have setup environment variables on Heroku with username and password properly (100% sure). I have enabled less secure apps to get the application working at https://myaccount.google.com/lesssecureapps. No 2-factor authentication. I have enabled captcha to allow to login from different devices at http://www.google.com/accounts/DisplayUnlockCaptcha and still no emails are sent.

On Heroku logs I see that it says "Sending email to...", it renders the template fine, no errors whatsoever but I don't receive any emails. I've checked Spam folder as well but no emails there.

production.rb

  config.action_mailer.default_url_options = { host: 'my_app.herokuapp.com' }
  config.action_mailer.perform_caching = false
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default :charset => "utf-8"

What am I missing?

Upvotes: 2

Views: 2146

Answers (1)

Mark Locklear
Mark Locklear

Reputation: 5325

This is an active app I have had forever where the mail still works. Try changing the auth type to a symbol rather than a string. So :plain instead of 'plain'.

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

 config.action_mailer.default_url_options = { :host => 'blarg.heroku.com' }
  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"

Upvotes: 1

Related Questions