Heroku不使用Gmail SMTP发送电子邮件

时间:2016-03-27 05:52:22

标签: ruby-on-rails ruby heroku devise

应用程序适用于所有内容,我尝试使用Confirmable with Devise,在我的Rails应用程序上它说电子邮件已发送,但我从未收到它。我通过SMTP配置Gmail。

感谢。

Heroku日志:

sList.Add(new MH_ScriptManager("start", "You awaken in a sweltering room..."));

ENV / production.rb

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"=>"smith.hampton23@gmail.com"}, "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", "smith.hampton23@gmail.com"]]
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", "smith.hampton23@gmail.com"]]
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 smith.hampton23@gmail.com (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: smith.hampton23@gmail.com
2016-03-27T04:49:33.194409+00:00 app[web.1]: Reply-To: smith.hampton23@gmail.com
2016-03-27T04:49:33.194410+00:00 app[web.1]: To: smith.hampton23@gmail.com
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 smith.hampton23@gmail.com!</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

3 个答案:

答案 0 :(得分:7)

如果您想通过Gmail smtp发送电子邮件,则需要检查两件重要事项:

  1. 您的应用配置:

    • 主持人:smtp.gmail.com
    • 端口:587465(tls为587,ssl为465)
    • 协议:tlsssl
    • 用户:YOUR_USERNAME@gmail.com
    • 密码:YOUR_PASSWORD
  2. 指定的Gmail帐户设置:

答案 1 :(得分:3)

我遇到了类似的问题。我遇到的问题是我没有告诉Heroku将我的配置变量复制到Heroku作为环境变量。我在输入此命令后使用了figaro gem和smtp电子邮件:

figaro heroku:set -e production

我建议您确保使用正确的Gmail用户名和密码。

有关详细信息,请查看本教程。我可以确认它有效 http://usingname.space/2015/07/25/gmail-smtp-ruby-on-rails-actionmailer-and-you/

答案 2 :(得分:-1)

首先heroku不允许免费发送邮件,您需要设置信用卡详细信息以发送邮件, 其次

检查您是否正确配置

打开development.rb并使用以下内容进行更新

config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host:'localhost', port: '3000' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"
  config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 25,
      :domain => 'localhost:3000',
      :user_name => "email id",
      :password => "password",
      :authentication => :plain,
      :enable_starttls_auto => true
  }