我一直试图使用Rails发送电子邮件' ActionMailer正在制作中。它在开发中运行良好,但是当我尝试生产时,我得到EOFError
。这些日志对我来说并不是很有帮助,所以有人能指出我如何调试它的正确方向吗?或者,如果你以前遇到过这种情况,你是如何解决的?
这是我的生产配置:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 465,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"],
authentication: :login,
enable_starttls_auto: true
}
除用户名和密码外,它与我的开发配置完全相同。虽然如果我在开发中使用prod凭证,它仍然有效。我正在使用端口465,因为这是我能够成功用于telnet的端口(我无法通过telnet连接到带有587的google smtp服务器)。
以下是我尝试发送电子邮件时收到的日志:
[#15945] INFO -- : [ActiveJob] [ActionMailer::DeliveryJob] [ae94a390-be07-4bdf-9fc5-dc7a58dd36ef] Performing ActionMailer::DeliveryJob from Inline(mailers) with arguments: "IndexMailer", "send_reset_password_email", "deliver_now!", gid://api/User::Student/4, "uaymjejb"
[#15945] DEBUG -- : [ActiveJob] [ActionMailer::DeliveryJob] [ae94a390-be07-4bdf-9fc5-dc7a58dd36ef]
IndexMailer#send_reset_password_email: processed outbound mail in 153.7ms
[#15945] INFO -- : [ActiveJob] [ActionMailer::DeliveryJob] [ae94a390-be07-4bdf-9fc5-dc7a58dd36ef] Performed ActionMailer::DeliveryJob from Inline(mailers) in 10221.58ms
[#15945] DEBUG -- : (1.1ms) ROLLBACK
[#15945] INFO -- : Completed 500 Internal Server Error in 10368ms (ActiveRecord: 7.6ms)
[#15945] FATAL -- :
EOFError (end of file reached):
app/controllers/application_controller.rb:87:in `block in reset_password_transaction'
app/controllers/application_controller.rb:85:in `reset_password_transaction'
app/controllers/application_controller.rb:49:in `reset_password'
这是重置密码的代码块:
# application_controller
def reset_password_transaction(user, password)
user_params = { password: password, password_confirmation: password }
user.transaction do
if user.update user_params
IndexMailer.send_reset_password_email(user, password).deliver_later!
else
raise ActiveRecord::Rollback
end
end
end
# IndexMailer
def send_reset_password_email(user, password)
return mail(
to: user.email,
subject: "Your password has been reset!",
body: "Hey there!\n\n\n" +
"You have recently asked to reset your password. Your temporary password is #{ password }.\n\n" +
"You can reset your password through the settings once you login with your temporary password. Have a good day!")
end
由于这在开发中有效,我可以假设电子邮件内容没有问题(例如格式错误的代码),并且这必须是连接问题或其他问题。
如果有帮助的话,我正在使用Ruby v2.2.1p85和Rails v4.2.5.2。我尝试过以下方法:
rake tmp: clear
:plain
config.action_mailer.perform_deliveries
设为true 不确定我还没有尝试过什么。我想知道为什么EOFError
仅在生产中发生。