【发布时间】:2021-11-24 18:27:46
【问题描述】:
我想创建一个处理程序来拯救电子邮件(主要是因为超时错误),所以我可以稍后尝试重新发送它们。 其他人建议使用其中定义的 ActionMailer::DeliveryJob.rescue_from 的初始化程序(我们使用 Deliver_later,无法挽救它)。此外,我需要渲染电子邮件,因为我们的模板引用了 activerecord 模型,因此如果我在再次发送电子邮件之前渲染电子邮件,可能会发生变化。 我的问题是 ActionMailer::Base.mail 似乎在这里不可用:
ActionMailer::DeliveryJob.rescue_from(StandardError) do |exception|
attempt = EmailAttempt.new
attempt.error_class = exception.class.to_s
attempt.mailer = self.arguments[0]
attempt.email_template = self.arguments[1]
attempt.params = self.arguments[3]
attempt.enqueued_at = self.enqueued_at
attempt.timezone = self.timezone
attempt.email_body = ActionMailer::Base.mail(**self.arguments[3][:email]) do |format|
format.html do
render locals: self.arguments[3][:body]
end
end
attempt.save!
end
在调用邮件方法之前停止代码,只需将ActionMailer::Base.mail 放入调试控制台会产生“不可用”消息(该类似乎可用,ActionMailer::Base.methods 会打印很多东西,@ 987654323@不在其中)。
请忽略方法的参数化,这是一个非常正在进行的代码,但是一旦我弄清楚如何调用它,我就可以整理(我认为)给它提供哪些参数。
我绝对不会深入研究 Ruby 或 Rails,所以这可能是新手错误,但我们将不胜感激。
【问题讨论】:
标签: ruby-on-rails ruby actionmailer