0

我刚刚使用 heroku ( http://fast-reaches-9399.herokuapp.com/ ) 启动了我的 rails 应用程序。我希望人们能够在顶部的文本区域中输入内容,然后单击提交按钮,然后将文本区域中的内容通过电子邮件发送给我。不过,我真的遇到了麻烦。它在开发环境中重定向,但似乎没有发送电子邮件。我在生产中收到 500 错误。这是一些相关的代码...

application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery

  def email
    UserMailer.idea_bar(params[:message]).deliver
    redirect_to "/"  # how can I redirect to the page the user was just on?
  end
end

/mailers/user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "anonymous@collegeanswers.com", to: "info@collegeanswerz.com", subject: "collegeanswers"

  def idea_bar(message)
    mail(:body => message)
  end
end

application.html.erb(布局文件)

<div class="idea_bar">
    <div class="left_idea_bar">
        <p>Ideas, comments, questions, suggestions?  Help us help you!</p>
        <%= form_tag("/application_controller/email", :method => "post", :id => "idea_bar_form") do %>
          <%= text_area_tag('message', nil, :size => "60x4", :id => "message", :name => "message") %> <br />
          <%= label_tag(:email, "• include your email if you want a response:") %>
          <%= text_field_tag(:email, nil, :id => "email", :size => "36") %>
    </div>
          <button id="submit" type="submit" form="idea_bar_form"><span id="big_submit">Send</span>
          <span id="small_submit"><br />&#8226 one click<br />&#8226 anonymous</span></button>
        <% end %>
</div>

/user_mailer/idea_bar.html.erb (测试文件。我希望电子邮件是文本区域中的内容,而不是这个)

<html>
    <head></head>
    <body>
        <p>hello</p>
    </body>
</html>

/user_mailer/idea_bar.text.erb

hello

日志

~/collegeanswerz >>  heroku logs -n 100
2013-06-24T02:10:39.511211+00:00 app[web.1]: [2013-06-24 02:10:39] INFO  WEBrick::HTTPServer#start: pid=2 port=37425
2013-06-24T02:10:39.628181+00:00 heroku[web.1]: State changed from starting to up
2013-06-24T02:10:39.971477+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-06-24T02:10:41.046475+00:00 app[web.1]: [2013-06-24 02:10:41] ERROR SignalException: SIGTERM
2013-06-24T02:10:41.046475+00:00 app[web.1]:    /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:98:in `select'
2013-06-24T02:10:46.399057+00:00 app[web.1]: Started GET "/" for 150.212.18.15 at 2013-06-24 02:10:46 +0000
2013-06-24T02:10:46.588166+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=1ms service=198ms status=200 bytes=14988
2013-06-24T02:10:46.547918+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2013-06-24T02:10:46.581761+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (3.8ms)
2013-06-24T02:10:46.584211+00:00 app[web.1]: Completed 200 OK in 36ms (Views: 35.8ms | ActiveRecord: 0.0ms)
2013-06-24T02:10:46.827096+00:00 heroku[router]: at=info method=GET path=/assets/home-73d942132cfdcc305dabf385494f8201.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=1ms service=6ms status=200 bytes=1884
2013-06-24T02:10:46.814074+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=3ms service=10ms status=200 bytes=1643
2013-06-24T02:10:46.834802+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=15ms status=200 bytes=156605
2013-06-24T02:10:47.262693+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=4ms service=6ms status=200 bytes=0
2013-06-24T02:10:49.760439+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2013-06-24T02:10:49.760205+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
2013-06-24T02:10:52.386481+00:00 heroku[web.1]: Process exited with status 137
2013-06-24T02:15:55.505285+00:00 app[web.1]: Started GET "/" for 67.171.66.44 at 2013-06-24 02:15:55 +0000
2013-06-24T02:15:55.510268+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2013-06-24T02:15:55.512568+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (1.6ms)
2013-06-24T02:15:55.514297+00:00 app[web.1]: Completed 200 OK in 4ms (Views: 3.7ms | ActiveRecord: 0.0ms)
2013-06-24T02:15:55.518380+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=7ms service=23ms status=200 bytes=14988
2013-06-24T02:15:55.739788+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=3ms service=6ms status=200 bytes=1643
2013-06-24T02:15:55.786186+00:00 heroku[router]: at=info method=GET path=/assets/home-73d942132cfdcc305dabf385494f8201.css host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=2ms service=5ms status=200 bytes=1884
2013-06-24T02:15:55.854372+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=3ms service=26ms status=200 bytes=156605
2013-06-24T02:19:33.509774+00:00 app[web.1]: Started GET "/colleges" for 150.212.18.15 at 2013-06-24 02:19:33 +0000
2013-06-24T02:19:33.513257+00:00 app[web.1]: Processing by StaticPagesController#colleges as HTML
2013-06-24T02:19:33.523421+00:00 heroku[router]: at=info method=GET path=/colleges host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=21ms status=304 bytes=0
2013-06-24T02:19:33.524174+00:00 app[web.1]: Completed 200 OK in 11ms (Views: 10.4ms | ActiveRecord: 0.0ms)
2013-06-24T02:19:33.522339+00:00 app[web.1]:   Rendered static_pages/colleges.html.erb within layouts/application (7.7ms)
2013-06-24T02:19:33.753391+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=5ms status=304 bytes=0
2013-06-24T02:19:33.735957+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=6ms status=304 bytes=0
2013-06-24T02:19:33.811360+00:00 heroku[router]: at=info method=GET path=/assets/colleges-7adcb0138796cf2dd39ad973ccd58699.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=5ms service=6ms status=200 bytes=232
2013-06-24T02:19:33.972423+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=1ms service=6ms status=304 bytes=0
2013-06-24T02:19:35.619992+00:00 app[web.1]: Started GET "/university-of-pittsburgh" for 150.212.18.15 at 2013-06-24 02:19:35 +0000
2013-06-24T02:19:35.624209+00:00 app[web.1]:   Parameters: {"college"=>"university-of-pittsburgh"}
2013-06-24T02:19:35.624209+00:00 app[web.1]: Processing by CollegePagesController#college_page as HTML
2013-06-24T02:19:35.876371+00:00 app[web.1]:   Rendered college_pages/college_page.html.erb within layouts/application (20.9ms)
2013-06-24T02:19:35.878070+00:00 app[web.1]: Completed 200 OK in 254ms (Views: 50.0ms | ActiveRecord: 22.2ms)
2013-06-24T02:19:35.902402+00:00 heroku[router]: at=info method=GET path=/university-of-pittsburgh host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=7ms service=289ms status=200 bytes=29578
2013-06-24T02:19:35.993171+00:00 heroku[router]: at=info method=GET path=/assets/college_pages-72b79bbce46f6e1c4a7b947a635cb3ef.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=8ms status=200 bytes=4711
2013-06-24T03:23:03.750562+00:00 heroku[web.1]: Idling
2013-06-24T03:23:06.124578+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-06-24T03:23:06.590444+00:00 app[web.1]:    /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:98:in `select'
2013-06-24T03:23:06.590444+00:00 app[web.1]: [2013-06-24 03:23:06] ERROR SignalException: SIGTERM
2013-06-24T03:23:15.819421+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2013-06-24T03:23:15.819273+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
2013-06-24T03:23:17.542955+00:00 heroku[web.1]: Process exited with status 137
2013-06-24T03:23:17.555718+00:00 heroku[web.1]: State changed from up to down
2013-06-24T04:43:11.725754+00:00 heroku[web.1]: State changed from down to starting
2013-06-24T04:43:11.725389+00:00 heroku[web.1]: Unidling
2013-06-24T04:43:15.022448+00:00 heroku[web.1]: Starting process with command `bundle exec rails server -p 20121`
2013-06-24T04:43:19.525120+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-06-24T04:43:19.525120+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Call with -d to detach
2013-06-24T04:43:28.871809+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Rails 3.2.13 application starting in production on http://0.0.0.0:20121
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Booting WEBrick
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-06-24T04:43:29.530107+00:00 app[web.1]: [2013-06-24 04:43:29] INFO  WEBrick 1.3.1
2013-06-24T04:43:29.530107+00:00 app[web.1]: [2013-06-24 04:43:29] INFO  ruby 1.9.3 (2013-05-15) [x86_64-linux]
2013-06-24T04:43:29.530878+00:00 app[web.1]: [2013-06-24 04:43:29] INFO  WEBrick::HTTPServer#start: pid=2 port=20121
2013-06-24T04:43:30.022925+00:00 heroku[web.1]: State changed from starting to up
2013-06-24T04:43:31.838145+00:00 app[web.1]: Started GET "/" for 150.212.13.47 at 2013-06-24 04:43:31 +0000
2013-06-24T04:43:32.678465+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2013-06-24T04:43:32.889354+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (31.0ms)
2013-06-24T04:43:32.932875+00:00 app[web.1]: Completed 200 OK in 254ms (Views: 246.6ms | ActiveRecord: 0.0ms)
2013-06-24T04:43:32.949968+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="150.212.13.47" dyno=web.1 connect=2ms service=1132ms status=304 bytes=0
2013-06-24T04:43:53.901496+00:00 app[web.1]: Started GET "/" for 24.131.255.163 at 2013-06-24 04:43:53 +0000
2013-06-24T04:43:53.905840+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2013-06-24T04:43:53.918816+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (1.1ms)
2013-06-24T04:43:53.924969+00:00 app[web.1]: Completed 200 OK in 19ms (Views: 7.6ms | ActiveRecord: 0.0ms)
2013-06-24T04:43:53.927908+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=1ms service=44ms status=200 bytes=14988
2013-06-24T04:43:54.371502+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=4ms service=12ms status=304 bytes=0
2013-06-24T04:43:54.400418+00:00 heroku[router]: at=info method=GET path=/assets/home-73d942132cfdcc305dabf385494f8201.css host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=3ms service=27ms status=304 bytes=0
2013-06-24T04:43:54.404305+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=1ms service=18ms status=304 bytes=0
2013-06-24T04:43:54.987065+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=2ms service=6ms status=304 bytes=0
2013-06-24T04:44:00.837309+00:00 app[web.1]: Started POST "/application_controller/email" for 24.131.255.163 at 2013-06-24 04:44:00 +0000
2013-06-24T04:44:00.845288+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"MubEQddsKvR/QBLZtZKCt8TF9EiUSHjSTpxtSB5mAhE=", "message"=>"testing", "email"=>""}
2013-06-24T04:44:00.845096+00:00 app[web.1]: Processing by ApplicationController#email as HTML
2013-06-24T04:44:00.946113+00:00 app[web.1]: 
2013-06-24T04:44:00.946113+00:00 app[web.1]: Sent mail to info@collegeanswerz.com (16ms)
2013-06-24T04:44:00.946346+00:00 app[web.1]: Completed 500 Internal Server Error in 101ms
2013-06-24T04:44:00.948747+00:00 app[web.1]: 
2013-06-24T04:44:00.948747+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2013-06-24T04:44:00.948747+00:00 app[web.1]:   app/controllers/application_controller.rb:5:in `email'
2013-06-24T04:44:00.948747+00:00 app[web.1]: 
2013-06-24T04:44:00.948747+00:00 app[web.1]: 
2013-06-24T04:44:00.952511+00:00 heroku[router]: at=info method=POST path=/application_controller/email host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=1ms service=126ms status=500 bytes=643
2013-06-24T04:44:13.657925+00:00 app[web.1]: Started POST "/application_controller/email" for 24.131.255.163 at 2013-06-24 04:44:13 +0000
2013-06-24T04:44:13.662188+00:00 app[web.1]: Processing by ApplicationController#email as HTML
2013-06-24T04:44:13.662374+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"MubEQddsKvR/QBLZtZKCt8TF9EiUSHjSTpxtSB5mAhE=", "message"=>"testing with test email", "email"=>"test email"}
2013-06-24T04:44:13.690119+00:00 heroku[router]: at=info method=POST path=/application_controller/email host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=3ms service=42ms status=500 bytes=643
2013-06-24T04:44:13.690067+00:00 app[web.1]:   app/controllers/application_controller.rb:5:in `email'
2013-06-24T04:44:13.690067+00:00 app[web.1]: 
2013-06-24T04:44:13.686636+00:00 app[web.1]: 
2013-06-24T04:44:13.686636+00:00 app[web.1]: Sent mail to info@collegeanswerz.com (15ms)
2013-06-24T04:44:13.690067+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2013-06-24T04:44:13.690067+00:00 app[web.1]: 
2013-06-24T04:44:13.690067+00:00 app[web.1]: 
2013-06-24T04:44:13.687154+00:00 app[web.1]: Completed 500 Internal Server Error in 25ms
~/collegeanswerz

4

2 回答 2

1

您可能会看到连接被拒绝错误,因为不允许您连接到 Heroku 上的本地 SMTP 服务器,这是不允许的。

您需要使用外部 SMTP 服务。Heroku 为多个提供外部 SMTP 服务的提供商提供插件,这些服务在其插件页面上列出:( https://addons.heroku.com/#email-sms )。每个附加组件都提供有关如何配置应用程序的说明

您还可以使用您拥有帐户的标准邮件服务,并通过 ActionMailer 对其进行配置。如果您有 GMail 帐户,您可以在 config/environments/production.rb 中尝试类似的操作。

http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

于 2013-06-24T05:43:02.630 回答
0

从提供的日志中可以清楚地看出,您收到错误是因为 Rails ActionMailer 无法连接到 SMTP 服务器。要在生产中调试此问题,您可以将配置更改development.rb为:

config.action_mailer.raise_delivery_errors = true

所以你会在开发中看到邮件程序异常。当您有确切的错误消息时,您可以更新有问题的日志以获得进一步的帮助。

于 2013-06-24T06:25:08.103 回答