如何使用SendGrid发送多个电子邮件? [英] How to send multiple emails with SendGrid?

查看:544
本文介绍了如何使用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发送多个电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆