ActionMailer有时不发送? [英] ActionMailer sometimes not sending?
问题描述
我遇到一个问题,即ActionMailer有时不发送电子邮件。它是可复制的,并且在某些时候会影响某些人,尽管导致它是一个谜。
尽管 config.action_mailer,它却默默地失败了。
它进入mail()例程,声称已渲染了模板:
渲染的notifier / notify_comment.html.erb(0.9毫秒)
,然后跳过传递内容,移至下一个。下一个呈现&交付没问题。传递电子邮件后,它们还会打印到控制台上,因此我可以看到它。每封电子邮件的内容都是相同的,只是收件人是不同的。
我不明白为什么这是断断续续的。
我该如何调试它?
每个邮件发件人实例只能发送1封电子邮件。 p>
邮件中是否有类似这样的代码?
@ subscribers.each做| s |
mail(
:to => s.email,
:subject => Foo Foo,
:from => someone@example.com,
:template_name =>'template_name'
)。交付
结束
这似乎不起作用。遍历邮件程序外部的订户,并调用一次:
在控制器或模型中:
@ subscribers.each做| s |
Notifier.send_to_subscriber(s,@comment)
结束
这是我的有Rails 3.2.2的经验。 FWIW,我认为发生的事情是邮件对象超出范围。
这种方法可能很慢,因此请确保在单独的线程中发送电子邮件。
p>参考和想法:如何使用SendGrid发送多封电子邮件?
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?
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?
这篇关于ActionMailer有时不发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!