将电子邮件发送从 AR_Mailer 切换到 DelayedJob 后丢失值

发布于 2024-10-15 22:44:58 字数 854 浏览 2 评论 0原文

我已经使用 AR_Mailer 大约 6 个月了,从未遇到过任何问题。我最近为一些管理后台作业添加了 DelayedJob。由于 DelayedJob 也可以很好地处理电子邮件(感谢 DelayedMailer gem),因此我从应用程序中完全删除了 AR_Mailer。

除了这封电子邮件之外,一切都很顺利。自动生成的密码现已丢失。

#app/models/notifier.rb 
def activation_instructions(user)
 from          default_email
 @bcc          = BACK_UP
 @subject      = "Activation instructions" 
 recipients    user.email
 sent_on       Time.now
 body          :root_url => root_url, :user => user
end

#app/views/notifier/activation_instructions.erb
Thanks for signing up.

Your password is <%[email protected]%>. For security reasons please change this on your first connection.

[....]

知道为什么会出现这个错误吗? 谢谢!

配置:Rails 2.3.2 &延迟作业 2.0.4

I've been using AR_Mailer for about 6 months without ever running into problems. I recently added DelayedJob for some administrative background jobs. Since DelayedJob also handles emails very well (thanks to DelayedMailer gem) I completely removed AR_Mailer from my application.

Everything works perfectly except this email. The password that is generated automatically is now lost.

#app/models/notifier.rb 
def activation_instructions(user)
 from          default_email
 @bcc          = BACK_UP
 @subject      = "Activation instructions" 
 recipients    user.email
 sent_on       Time.now
 body          :root_url => root_url, :user => user
end

#app/views/notifier/activation_instructions.erb
Thanks for signing up.

Your password is <%[email protected]%>. For security reasons please change this on your first connection.

[....]

Any idea on why this bug occurs?
Thanks!

Configuration: Rails 2.3.2 & DelayedJob 2.0.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千笙结 2024-10-22 22:44:58

我发现问题出在哪里了。我在数据库中查看了在elasted_jobs表中创建的条目:

  --- !ruby/struct:Delayed::PerformableMethod
  object: LOAD;Notifier
  method: :deliver_activation_instructions!
  args:
  - LOAD;User;589

在发送电子邮件之前,delayed_job从数据库重新加载user参数。在这种情况下,密码会丢失,因为它没有存储在数据库中。

因此,我更新了代码以便显式传递密码:

#app/models/notifier.rb 
def activation_instructions(user, password)
 from          default_email
 @bcc          = BACK_UP
 @subject      = "Activation instructions" 
 recipients    user.email
 sent_on       Time.now
 body          :root_url => root_url, :user => user, :password => password
end

#app/views/notifier/activation_instructions.erb
Thanks for signing up.

Your password is <%=@password-%>. For security reasons please change this on your first connection.

[....]

希望这对其他人也有帮助!

I found out where the problem was. I looked in the database at the entry created in the delayed_jobs table:

  --- !ruby/struct:Delayed::PerformableMethod
  object: LOAD;Notifier
  method: :deliver_activation_instructions!
  args:
  - LOAD;User;589

The user parameter is reloaded from the database by delayed_job before sending the email. In that case, the password is lost because it's not stored in the database.

So I've updated the code in order to pass explicitly the password:

#app/models/notifier.rb 
def activation_instructions(user, password)
 from          default_email
 @bcc          = BACK_UP
 @subject      = "Activation instructions" 
 recipients    user.email
 sent_on       Time.now
 body          :root_url => root_url, :user => user, :password => password
end

#app/views/notifier/activation_instructions.erb
Thanks for signing up.

Your password is <%=@password-%>. For security reasons please change this on your first connection.

[....]

Hope this helps other too!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文