OhDeer
OhDeer

Reputation: 131

Rails 5 app in Heroku won't send an email setup with gmal

I am stuck and cannot find any help online:

I am trying to send out emails on user registration and I have the same configuration which is working on development, but I cannot find a way to make it work in heroku

config.action_mailer.default_url_options = { host: 'www.hiddendomain.com' }
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :authentication => :plain,
    :domain => ENV['GMAIL_SMTP_USERNAME'],
    :user_name => ENV['GMAIL_SMTP_USERNAME'],
    :password => ENV['GMAIL_SMTP_PASSWORD'],
  }

  config.action_mailer.perform_deliveries = true

Error:

2017-07-27T07:41:45.175561+00:00 app[web.1]: I, [2017-07-27T07:41:45.175497 #4]  INFO -- : [a6ec5129-53a4-420a-b319-9cc6d61cff16] Completed 500 Internal Server Error in 544ms (ActiveRecord: 9.0ms)

2017-07-27T07:41:45.175719+00:00 app[web.1]: F, [2017-07-27T07:41:45.175664 #4] FATAL -- : [a6ec5129-53a4-420a-b319-9cc6d61cff16]

2017-07-27T07:41:45.175791+00:00 app[web.1]: F, [2017-07-27T07:41:45.175729 #4] FATAL -- : [a6ec5129-53a4-420a-b319-9cc6d61cff16] EOFError (end of file reached):

2017-07-27T07:41:45.175853+00:00 app[web.1]: F, [2017-07-27T07:41:45.175794 #4] FATAL -- : [a6ec5129-53a4-420a-b319-9cc6d61cff16]

2017-07-27T07:41:45.175923+00:00 app[web.1]: F, [2017-07-27T07:41:45.175866 #4] FATAL -- : [a6ec5129-53a4-420a-b319-9cc6d61cff16]

The only difference from the development environment is the host line:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Upvotes: 0

Views: 309

Answers (3)

Leo
Leo

Reputation: 1773

In your config is line

:domain => ENV['GMAIL_SMTP_USERNAME']

It's wrong, because you have some env variable in field username. Domain should be "gmail.com", because you use gmails mail service from gmail.com:

config.action_mailer.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :authentication => :plain,
  :domain => "gmail.com",
  :user_name => ENV['GMAIL_SMTP_USERNAME'],
  :password => ENV['GMAIL_SMTP_PASSWORD'],
}

Upvotes: 1

Sanjiv
Sanjiv

Reputation: 843

Some apps and devices use less secure sign-in technology, turnon Allow less secure apps. Please go to my account in gmail: https://myaccount.google.com/lesssecureapps and turnon Allow less secure apps filter

Upvotes: 0

Nermin
Nermin

Reputation: 6100

The problem could be that gmail has strict options for sending emails over third party applications. You need to enable this option for you gmail account.

Make sure Enable is selected under Access for less secure apps.

Upvotes: 1

Related Questions