如何使用SendGrid发送多个电子邮件?

编程入门 行业动态 更新时间:2024-10-22 13:38:57
本文介绍了如何使用SendGrid发送多个电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果有一个用户,下面的代码似乎可以工作,但截断多个用户的电子邮件:

users.each do | user | mail(:to => user.email,:subject =>'Hi',:template_name =>'notification')。发送

这是发送几封电子邮件的正确方法吗?

  • Ruby on Rails 3.2.2
  • Heroku
  • SendGrid

解决方案

似乎问题在于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' ).deliver

Is 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发送多个电子邮件?

本文发布于:2023-11-06 06:36:08,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何使用   电子邮件   SendGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!