【问题标题】:Heroku not sending email with Gmail SMTPHeroku 不使用 Gmail SMTP 发送电子邮件
【发布时间】:2016-07-14 15:33:04
【问题描述】:

该应用程序一切正常,我正在尝试将 Confirmable 与 Devise 一起使用,在我的 Rails 应用程序上它说电子邮件已发送,但我从未收到它。我正在通过 SMTP 使用 Gmail 对其进行配置。

谢谢。

Heroku 日志:

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

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
}

【问题讨论】:

  • 您检查过spam 文件夹吗?
  • 是的,我做了,但那里什么也没有

标签: ruby-on-rails ruby heroku devise


【解决方案1】:

我遇到了类似的问题。我遇到的问题是我没有告诉 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】:

    当您想通过 Gmail smtp 发送电子邮件时,您必须检查两件重要的事情:

    1. 您的应用配置:

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

    【讨论】:

    • 您好,我使用了两步验证并输入了应用密码,但仍然出现 SMTPAuthenticationError。你可以帮帮我吗?谢谢。
    • 嗨君,也许这些设置从那时起就已经过时了。没有两步验证是否可以正常工作?
    • 您好,Gex,可能是服务问题,等待一段时间后才能正常工作。感谢您的回复。
    • @Gex 你知道这样做的公共 github 存储库吗?看到一个如何做到这一点的例子真的很有帮助。
    • 感谢@Gex!步骤 2.2 使它对我有用!我已经尝试了 2 小时。
    【解决方案3】:

    首先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
      }
    

    【讨论】:

    • 但我认为您可以使用 gmail 免费发送电子邮件。
    • 我应该使用 sendgrid 吗?
    • "mailgun" 是免费的(有限制),但您需要在其中注册您的信用卡详细信息,Heroku 不提供免费邮寄服务。
    • 谢谢我使用它。
    • 我已经通过 Heroku 应用程序免费使用 Rails actionmailer 发送了电子邮件。
    猜你喜欢
    • 2014-10-19
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    相关资源
    最近更新 更多