ActionMailer sometimes not sending?

邮差的信 提交于 2019-12-10 17:54:52

问题


I have a problem where ActionMailer sometimes doesn't send emails. It is reproducible and affects certain people at certain times, although what is causing it is a mystery.

It fails silently, although config.action_mailer.raise_delivery_errors = true is set.

It enters the mail() routine, claims it has rendered the template:

Rendered notifier/notify_comment.html.erb (0.9ms)

And then skips the delivery and moves onto the next one. The next one is rendered & delivered no problem. When emails are delivered, they are also printed to the console, so I can see it. The content of every email is the same, only the recipient is different.

I cannot understand why this would be intermittent.

How can I go about debugging this?


回答1:


Each instance of the mailer can only send 1 email.

Do you have code that looks like this inside of the mailer?

@subscribers.each do |s|
  mail(
    :to => s.email,
    :subject => "Foo Foo",
    :from => "someone@example.com", 
    :template_name => 'template_name'
  ).deliver
end

This doesn't seem to work. Iterate over the subscribers outside of the mailer, and call it once:

In a controller or model:

@subscribers.each do |s|
  Notifier.send_to_subscriber(s, @comment)
end

This was my experience in Rails 3.2.2. FWIW, I think what happens is that the mail object falls out of scope.

This approach may be slow, so be sure to send emails in a separate thread.

Reference and ideas: How to send multiple emails with SendGrid?



来源:https://stackoverflow.com/questions/13050224/actionmailer-sometimes-not-sending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!