Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku not sending email with Gmail SMTP

The app works everything, I'm trying to use Confirmable with Devise, on my Rails app it says that the email was sent, but I never receive it. I'm configuring it with Gmail though SMTP.

Thanks.

the Heroku log:

2016-03-27T04:49:23.448947+00:00 app[web.1]:   Rendered devise/shared/_links.html.erb (1.0ms)
2016-03-27T04:49:23.449047+00:00 app[web.1]:   Rendered devise/sessions/new.html.erb within layouts/application (9.4ms)
2016-03-27T04:49:23.450618+00:00 app[web.1]:   Rendered layouts/_navbar.html.erb (0.5ms)
2016-03-27T04:49:23.451085+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.1ms)
2016-03-27T04:49:23.451438+00:00 app[web.1]: Completed 200 OK in 14ms (Views: 12.2ms | ActiveRecord: 0.0ms)
2016-03-27T04:49:23.949248+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=my-task-tracker.herokuapp.com request_id=146e1632-c484-471f-97c3-feaaf1a1b2ed fwd="108.219.46.125" dyno=web.1 connect=3ms service=11ms status=304 bytes=133
2016-03-27T04:49:29.128082+00:00 heroku[router]: at=info method=GET path="/users/confirmation/new" host=my-task-tracker.herokuapp.com request_id=1b9d8a7c-7c9e-4e50-a4f0-4be476c92dfb fwd="108.219.46.125" dyno=web.1 connect=1ms service=33ms status=200 bytes=3182
2016-03-27T04:49:29.132299+00:00 app[web.1]: Started GET "/users/confirmation/new" for 108.219.46.125 at 2016-03-27 04:49:29 +0000
2016-03-27T04:49:29.137153+00:00 app[web.1]: Processing by Devise::ConfirmationsController#new as HTML
2016-03-27T04:49:29.151819+00:00 app[web.1]:   Rendered devise/shared/_links.html.erb (1.4ms)
2016-03-27T04:49:29.151898+00:00 app[web.1]:   Rendered devise/confirmations/new.html.erb within layouts/application (6.7ms)
2016-03-27T04:49:29.153383+00:00 app[web.1]:   Rendered layouts/_navbar.html.erb (0.5ms)
2016-03-27T04:49:29.153706+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.1ms)
2016-03-27T04:49:29.154027+00:00 app[web.1]: Completed 200 OK in 17ms (Views: 15.5ms | ActiveRecord: 0.0ms)
2016-03-27T04:49:29.386263+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=my-task-tracker.herokuapp.com request_id=c0dbab1b-9032-4787-bb64-3070feb0066b fwd="108.219.46.125" dyno=web.1 connect=1ms service=7ms status=304 bytes=133
2016-03-27T04:49:32.066230+00:00 app[web.1]: Started POST "/users/confirmation" for 108.219.46.125 at 2016-03-27 04:49:32 +0000
2016-03-27T04:49:32.068692+00:00 app[web.1]: Processing by Devise::ConfirmationsController#create as HTML
2016-03-27T04:49:32.068831+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"HnARWykNdBAKSmewO6IZaOQ4Vokg9V46SxzCUADvtybFpbVVfuErGn/QLRQXWc4j79Krq9sAfBveAjR1ar9C7g==", "user"=>{"email"=>"[email protected]"}, "commit"=>"Resend confirmation instructions"}
2016-03-27T04:49:32.082510+00:00 app[web.1]:   User Load (1.0ms)  SELECT  "users".* FROM "users" WHERE "users"."unconfirmed_email" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["unconfirmed_email", "[email protected]"]]
2016-03-27T04:49:32.091027+00:00 app[web.1]:   User Load (3.1ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["email", "[email protected]"]]
2016-03-27T04:49:32.103821+00:00 app[web.1]:    (12.0ms)  BEGIN
2016-03-27T04:49:32.126821+00:00 app[web.1]:    (20.9ms)  COMMIT
2016-03-27T04:49:32.227009+00:00 app[web.1]:   Rendered devise/mailer/confirmation_instructions.html.erb (8.6ms)
2016-03-27T04:49:32.973627+00:00 app[web.1]: 
2016-03-27T04:49:32.973641+00:00 app[web.1]: Devise::Mailer#confirmation_instructions: processed outbound mail in 843.7ms
2016-03-27T04:49:33.194388+00:00 app[web.1]: 
2016-03-27T04:49:33.194402+00:00 app[web.1]: Sent mail to [email protected] (220.6ms)
2016-03-27T04:49:33.194407+00:00 app[web.1]: Date: Sun, 27 Mar 2016 04:49:32 +0000
2016-03-27T04:49:33.194408+00:00 app[web.1]: From: [email protected]
2016-03-27T04:49:33.194409+00:00 app[web.1]: Reply-To: [email protected]
2016-03-27T04:49:33.194410+00:00 app[web.1]: To: [email protected]
2016-03-27T04:49:33.194413+00:00 app[web.1]: Message-ID: <56f7665cef03b_33febb8de74141bf@29f38684-21c7-41d6-821e-42ae72d533ac.mail>
2016-03-27T04:49:33.194414+00:00 app[web.1]: Subject: Confirmation instructions
2016-03-27T04:49:33.194415+00:00 app[web.1]: Mime-Version: 1.0
2016-03-27T04:49:33.194415+00:00 app[web.1]: Content-Type: text/html;
2016-03-27T04:49:33.194416+00:00 app[web.1]:  charset=UTF-8
2016-03-27T04:49:33.194417+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2016-03-27T04:49:33.194418+00:00 app[web.1]: <p>Welcome [email protected]!</p>
2016-03-27T04:49:33.194417+00:00 app[web.1]: 
2016-03-27T04:49:33.194419+00:00 app[web.1]: 
2016-03-27T04:49:33.194420+00:00 app[web.1]: <p>You can confirm your account email through the link below:</p>
2016-03-27T04:49:33.194421+00:00 app[web.1]: 
2016-03-27T04:49:33.194423+00:00 app[web.1]: <p><a href="https://my-task-tracker.herokuapp.com/users/confirmation?confirmation_token=yBnGnJEZkkaL-pU7_Y_U&amp;locale=en">Confirm my account</a></p>
2016-03-27T04:49:33.194424+00:00 app[web.1]: 
2016-03-27T04:49:33.201842+00:00 app[web.1]: Redirected to https://my-task-tracker.herokuapp.com/users/sign_in
2016-03-27T04:49:33.202005+00:00 app[web.1]: Completed 302 Found in 1133ms (ActiveRecord: 37.8ms)
2016-03-27T04:49:33.187258+00:00 heroku[router]: at=info method=POST path="/users/confirmation" host=my-task-tracker.herokuapp.com request_id=3fa250b9-23e4-43f7-8e10-4f37e54d9a79 fwd="108.219.46.125" dyno=web.1 connect=1ms service=1162ms status=302 bytes=1245
2016-03-27T04:49:33.361655+00:00 app[web.1]: Started GET "/users/sign_in" for 108.219.46.125 at 2016-03-27 04:49:33 +0000
2016-03-27T04:49:33.372833+00:00 app[web.1]: Processing by Devise::SessionsController#new as HTML
2016-03-27T04:49:33.400388+00:00 app[web.1]:   Rendered devise/shared/_links.html.erb (1.3ms)
2016-03-27T04:49:33.400564+00:00 app[web.1]:   Rendered devise/sessions/new.html.erb within layouts/application (24.7ms)
2016-03-27T04:49:33.402011+00:00 app[web.1]:   Rendered layouts/_navbar.html.erb (0.6ms)
2016-03-27T04:49:33.402772+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.1ms)
2016-03-27T04:49:33.403290+00:00 app[web.1]: Completed 200 OK in 30ms (Views: 28.3ms | ActiveRecord: 0.0ms)
2016-03-27T04:49:33.376910+00:00 heroku[router]: at=info method=GET path="/users/sign_in" host=my-task-tracker.herokuapp.com request_id=72189b98-69bc-415f-ade7-a21856684a0a fwd="108.219.46.125" dyno=web.1 connect=5ms service=47ms status=200 bytes=4220
2016-03-27T05:23:51.692897+00:00 heroku[web.1]: Idling
2016-03-27T05:23:51.693798+00:00 heroku[web.1]: State changed from up to down
2016-03-27T05:23:57.760741+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-03-27T05:23:59.284360+00:00 app[web.1]:    /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:174:in `select'
2016-03-27T05:23:59.284343+00:00 app[web.1]: [2016-03-27 05:23:59] FATAL SignalException: SIGTERM
2016-03-27T05:23:59.284363+00:00 app[web.1]:    /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:174:in `block in start'
2016-03-27T05:23:59.284364+00:00 app[web.1]:    /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:32:in `start'
2016-03-27T05:23:59.284365+00:00 app[web.1]:    /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:162:in `start'
2016-03-27T05:23:59.284365+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:34:in `run'
2016-03-27T05:23:59.284367+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
2016-03-27T05:23:59.284366+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
2016-03-27T05:23:59.284367+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
2016-03-27T05:23:59.284368+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
2016-03-27T05:23:59.284369+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2016-03-27T05:23:59.284369+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
2016-03-27T05:23:59.284370+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
2016-03-27T05:23:59.284390+00:00 app[web.1]:    bin/rails:9:in `require'
2016-03-27T05:23:59.284391+00:00 app[web.1]:    bin/rails:9:in `<main>'
2016-03-27T05:23:59.284464+00:00 app[web.1]: [2016-03-27 05:23:59] INFO  going to shutdown ...
2016-03-27T05:23:59.284516+00:00 app[web.1]: [2016-03-27 05:23:59] INFO  WEBrick::HTTPServer#start done.
2016-03-27T05:23:59.284544+00:00 app[web.1]: Exiting
2016-03-27T05:24:00.235601+00:00 heroku[web.1]: Process exited with status 143
2016-03-27T05:29:00.462487+00:00 heroku[web.1]: Unidling
2016-03-27T05:29:00.462791+00:00 heroku[web.1]: State changed from down to starting
2016-03-27T05:29:03.166146+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 18537 -e production`
2016-03-27T05:29:06.739510+00:00 app[web.1]: [2016-03-27 05:29:06] INFO  WEBrick 1.3.1
2016-03-27T05:29:06.739563+00:00 app[web.1]: [2016-03-27 05:29:06] INFO  ruby 2.2.4 (2015-12-16) [x86_64-linux]
2016-03-27T05:29:06.739784+00:00 app[web.1]: [2016-03-27 05:29:06] INFO  WEBrick::HTTPServer#start: pid=3 port=18537
2016-03-27T05:29:07.331731+00:00 heroku[web.1]: State changed from starting to up
2016-03-27T05:29:08.588190+00:00 heroku[router]: at=info method=GET path="/" host=my-task-tracker.herokuapp.com request_id=4343eecf-3333-496c-936d-9881c5d12412 fwd="108.219.46.125" dyno=web.1 connect=0ms service=92ms status=302 bytes=1122
2016-03-27T05:29:08.517272+00:00 app[web.1]: => Booting WEBrick
2016-03-27T05:29:08.517309+00:00 app[web.1]: => Rails 4.2.4 application starting in production on http://0.0.0.0:18537
2016-03-27T05:29:08.517311+00:00 app[web.1]: => Run `rails server -h` for more startup options
2016-03-27T05:29:08.517312+00:00 app[web.1]: => Ctrl-C to shutdown server
2016-03-27T05:29:08.517313+00:00 app[web.1]: Started GET "/" for 108.219.46.125 at 2016-03-27 05:29:08 +0000
2016-03-27T05:29:08.555988+00:00 app[web.1]: Processing by PagesController#index as HTML
2016-03-27T05:29:08.565676+00:00 app[web.1]: Completed 401 Unauthorized in 10ms (ActiveRecord: 0.0ms)
2016-03-27T05:29:08.953091+00:00 heroku[router]: at=info method=GET path="/users/sign_in" host=my-task-tracker.herokuapp.com request_id=69e03185-2d8f-41c5-ba23-d62fe66fdf6e fwd="108.219.46.125" dyno=web.1 connect=0ms service=57ms status=200 bytes=4002
2016-03-27T05:29:08.917010+00:00 app[web.1]: Started GET "/users/sign_in" for 108.219.46.125 at 2016-03-27 05:29:08 +0000
2016-03-27T05:29:08.919553+00:00 app[web.1]: Processing by Devise::SessionsController#new as HTML
2016-03-27T05:29:08.961087+00:00 app[web.1]:   Rendered devise/shared/_links.html.erb (2.9ms)
2016-03-27T05:29:08.961219+00:00 app[web.1]:   Rendered devise/sessions/new.html.erb within layouts/application (10.0ms)
2016-03-27T05:29:08.964675+00:00 app[web.1]:   Rendered layouts/_navbar.html.erb (1.4ms)
2016-03-27T05:29:08.965909+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.3ms)
2016-03-27T05:29:08.966140+00:00 app[web.1]: Completed 200 OK in 47ms (Views: 18.3ms | ActiveRecord: 5.9ms)
2016-03-27T05:29:09.845722+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=my-task-tracker.herokuapp.com request_id=5893b11b-579b-4937-9dc7-1b4b63c7ea3f fwd="108.219.46.125" dyno=web.1 connect=0ms service=4ms status=304 bytes=133

env/production.rb

config.action_mailer.default_url_options = { :host => 'https://my-task-    tracker.herokuapp.com' }
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                 => 587,
:user_name            => ENV["GMAIL_USERNAME"],
:password             => ENV["GMAIL_PASSWORD"],
:authentication       => "plain",
:enable_starttls_auto => true
}
like image 868
Matthew Smith Avatar asked Mar 27 '16 05:03

Matthew Smith


People also ask

Does Heroku have SMTP server?

You can indeed use external SMTP providers to send email through Heroku (I do this on several of the apps I run).

Does Heroku support email?

If you are unable to log in or access your account, you may submit a ticket by sending an e-mail from your Heroku account email address to [email protected].


Video Answer


1 Answers

You have to check two important things when you want to send emails via Gmail smtp:

  1. Your apps configuration:

    • host: smtp.gmail.com
    • port: 587 or 465 (587 for tls, 465 for ssl)
    • protocol: tls or ssl
    • user: [email protected]
    • password: YOUR_PASSWORD
  2. The given Gmail account settings:

    • If you've turned on 2-Step Verification for your account, you might need to enter an App password.
    • Without 2-Step Verification:
      1. Allow less secure apps access to your account.
      2. Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password.
like image 185
Gex Avatar answered Sep 27 '22 19:09

Gex