当我通过我的git连接到生产环境时,我的SMTP可以正常工作,但是当我通过heroku连接时,它并没有
我试图创建一个应用程序,每当有人发表评论时,都会发送一封电子邮件。
当我通过" rails s --environment = production"在git中,一切都按预期工作,但是当我将我的应用程序部署到heroku时,我得到了一个500"(内部服务器错误)"在我的chrome控制台中,没有发送任何内容。
- 这些是我的生产动作_邮件配置:
config.action_mailer.default_url_options = { host: "warm-mesa-2622.herokuapp.com" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.interativasistemas.com",
:port => 587,
:domain => 'warm-mesa-2622.herokuapp.com',
:user_name => 'my_user@interativasistemas.com',
:password => <password>,
:authentication => 'login',
:enable_starttls_auto => true,
:enable_ssl => true,
:openssl_verify_mode => 'none'
}
- 这是我的 git连接中的日志,当我创建新评论时,一切都按预期进行:
Started POST "/jobs/15/comments" for 127.0.0.1 at 2014-08-22 15:33:19 -0300
Processing by CommentsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"r4fDJrBWRjKgNqwMlfqRAzMZO8fPC
vjaPOxVfAghGb0=", "comment"=>{"name"=>"Comment", "body"=>"Comment Post."}, "comm
it"=>"Send", "job_id"=>"15"}
Rendered company_mailer/new_comment.html.erb (1.0ms)
Rendered company_mailer/new_comment.text.erb (1.0ms)
Sent mail to mella.neto@gmail.com (1514ms)
Rendered comments/_comment.html.erb (15.0ms)
Rendered comments/create.js.erb (20.0ms)
Completed 200 OK in 5192ms (Views: 31.0ms | ActiveRecord: 3509.2ms)
cache: [POST /jobs/15/comments] invalidate, pass
- 这是 heroku连接上的相同日志,一切都出错,电子邮件未发送:
←[36m2014-08-22T18:37:22.843252+00:00 app[web.1]:←[0m Started POST "/jobs/15/com
ments" for 187.23.176.51 at 2014-08-22 18:37:22 +0000
←[36m2014-08-22T18:37:22.845655+00:00 app[web.1]:←[0m Processing by CommentsCont
roller#create as JS
←[36m2014-08-22T18:37:22.845725+00:00 app[web.1]:←[0m Parameters: {"utf8"=>"��
�", "authenticity_token"=>"e07XWzBXlkYBLVXIhGMCxVhekzMpayaGXrUoTH2Xgco=", "comme
nt"=>{"name"=>"Comment", "body"=>"Comment Body."}, "commit"=>"Send", "job_id"=>"
15"}
←[36m2014-08-22T18:37:22.866964+00:00 app[web.1]:←[0m Rendered company_mailer/
new_comment.html.erb (0.6ms)
←[36m2014-08-22T18:37:22.867544+00:00 app[web.1]:←[0m Rendered company_mailer/
new_comment.text.erb (0.3ms)
←[33m2014-08-22T18:37:23.213749+00:00 heroku[router]:←[0m at=info method=POST pa
th="/jobs/15/comments" host=warm-mesa-2622.herokuapp.com request_id=15dba4d8-7b2
7-4cf0-9da8-ea0b117201c0 fwd="187.23.176.51" dyno=web.1 connect=1ms service=373m
s status=500 bytes=1274
←[36m2014-08-22T18:37:23.203501+00:00 app[web.1]:←[0m
←[36m2014-08-22T18:37:23.203508+00:00 app[web.1]:←[0m Sent mail to mella.neto@gm
ail.com (327ms)
←[36m2014-08-22T18:37:23.203846+00:00 app[web.1]:←[0m Completed 500 Internal Ser
ver Error in 358ms
←[36m2014-08-22T18:37:23.205470+00:00 app[web.1]:←[0m
←[36m2014-08-22T18:37:23.205473+00:00 app[web.1]:←[0m Errno::ECONNREFUSED (Conne
ction refused - connect(2)):
←[36m2014-08-22T18:37:23.205475+00:00 app[web.1]:←[0m app/controllers/comments
_controller.rb:7:in `create'
←[36m2014-08-22T18:37:23.205476+00:00 app[web.1]:←[0m
←[36m2014-08-22T18:37:23.205478+00:00 app[web.1]:←[0m
←[36m2014-08-22T18:37:23.205798+00:00 app[web.1]:←[0m cache: [POST /jobs/15/comm
ents] invalidate, pass
这是我的 comments_controller创建功能:
def create
@job = Job.find(params[:job_id])
@comment = @job.comments.build(params[:comment])
if success = @comment.save
CompanyMailer.new_comment(@job, @comment).deliver
end
respond_to do |format|
format.html do
if success
flash[:notice] = "Comment was created with success!"
else
flash[:alert] = "Comment could not be created!"
end
redirect_to @job
end
format.js
end
end
还有我的 company_mailer ,它定义了电子邮件功能:
class CompanyMailer < ActionMailer::Base
default from: "my_user@interativasistemas.com"
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.company_mailer.new_comment.subject
#
def new_comment(job, comment)
@job = job
@comment = comment
@company = job.company
mail to: @company.email, subject: "New comment received"
end
end
有人能帮帮我吗?我使用ruby 1.9.3和rails 3.2.2
答案 0 :(得分:0)
要调试此类问题,您需要使用heroku run bash
然后rails s
或rails console
创建一次性dyno。