如果有一个用户,下面的代码似乎可以工作,但截断多个用户的电子邮件:
users.each do | user | mail(:to => user.email,:subject =>'Hi',:template_name =>'notification')。发送这是发送几封电子邮件的正确方法吗?
似乎问题在于Mailer的每个实例只能发送一封电子邮件。也许邮件对象正在超出范围,并被垃圾收集器清理干净......
这个解决方案的工作是迭代Mailer之外的用户,并为每个用户调用一次。它可能会很慢,但它应该发生在后台,所以它很好。
The following code seems to work if there is one user, but truncate the email for multiple users:
users.each do |user| mail( :to => user.email, :subject => 'Hi', :template_name => 'notification' ).deliverIs this the proper way to send a few emails?
- Ruby on Rails 3.2.2
- Heroku
- SendGrid
It seems that the problem is that each instance of the Mailer can only send one email. Perhaps the mail object is falling out of scope and getting cleaned up by the garbage collector...
The solution that worked was to iterate over the users outside of the Mailer, and call it once for each user. It may be slow but it should happen in the background anyway so it's fine.
更多推荐
如何使用SendGrid发送多个电子邮件?
发布评论