我是ActionMailer的新手,但我也阅读了其中的文档。我只是不确定Devise如何处理它。我正在使用Rails 5.1,但无法使Devise邮件程序在开发中工作。
尝试在开发中获取重置密码电子邮件时,出现以下错误:
EOFError in Devise::PasswordsController#create
{"utf8"=>"✓",
"authenticity_token"=>"token info",
"user"=>{"email"=>"user@email.com"},
"commit"=>"Send me reset password instructions"}
在服务器日志中:
Started POST "/users/password" for 127.0.0.1 at 2018-07-26 17:18:09 -0400
Processing by Devise::PasswordsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"token", "user"=>{"email"=>"user@email.com"}, "commit"=>"Send me reset password instructions"}
User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["email", "user@email.com"], ["LIMIT", 1]]
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["reset_password_token", "token"], ["LIMIT", 1]]
(0.3ms) BEGIN
SQL (0.7ms) UPDATE "users" SET "reset_password_token" = $1, "reset_password_sent_at" = $2, "updated_at" = $3 WHERE "users"."id" = $4 [["reset_password_token", "token"], ["reset_password_sent_at", "2018-07-26 21:18:10.075033"], ["updated_at", "2018-07-26 21:18:10.076032"], ["id", 2]]
(2.6ms) COMMIT
Rendering devise/mailer/reset_password_instructions.html.erb
Rendered devise/mailer/reset_password_instructions.html.erb (1.1ms)
Devise::Mailer#reset_password_instructions: processed outbound mail in 452.1ms
Sent mail to user@email.com (30027.6ms)
Date: Thu, 26 Jul 2018 17:18:11 -0400
To: user@email.com
Message-ID: <my system>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
... the view...
Completed 500 Internal Server Error in 31449ms (ActiveRecord: 5.6ms)
EOFError (end of file reached):
我已经设置了config / environments / development.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# Using MailCatcher server -- running @ 1080
config.action_mailer.smtp_settings = { address: "localhost", port: 1080 }
我正在运行MailCatcher服务器。当我将'raise_deliver_errors'= false设置为false时,我看到消息已发送,但MailCatcher却什么也没收到。
我有点困惑,我研究过的每一件事都说我只需要这样做就可以使它起作用-如果不需要,我不想与Devise Controllers一起玩。< / p>
谢谢!
答案 0 :(得分:0)
我所做的只是把这行代码从
config.action_mailer.delivery_method = :smtp
进入
config.action_mailer.delivery_method = :test
视图出现在日志中,当我在生产中配置Sendgrid时,电子邮件已正确发送。