将电子邮件发送给大量收件人的最佳做法(Rails + SendGrid) [英] Best practices for sending email to lots of recipients (Rails + SendGrid)

查看:139
本文介绍了将电子邮件发送给大量收件人的最佳做法(Rails + SendGrid)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将从Rails应用发送批量电子邮件并计划使用SendGrid。我假设最好向每个收件人发送一封单独​​的电子邮件(而不是为所有收件人使用BCC)。如果是这样的话,我是否应该使用类似DelayedJob的方法来将消息排列到SendGrid,或者一次性扔500条消息是否安全?感谢!

解决方案

500个消息对SendGrid来说真的没有那么多。这甚至不是他们的雷达。我曾在一家公司工作过,这家公司在一个月内发送了270万封电子邮件,即使这样也只是一个blip。



使用SendGrid API的功能,您不会发送500封电子邮件,您可以发送一封包含特定SendGrid API标头集的电子邮件。为什么?因为你有没有试过发送 500个个人电子邮件并计时需要多长时间?如何一封电子邮件?单一电子邮件将会更快。



SendGrid API有一个Ruby示例,在这里:
https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/ruby.html



这是相当长的缠绕和混乱,所以让我为你简化它。基本上,您可以在您的电子邮件中设置:

 标题[X-SMTPAPI] = {:to => array_of_recipients} .to_json 

然后SendGrid会解析它,然后发送一个 您将电子邮件发送给该收件人阵列。我似乎回想起,他们要求您限制每封电子邮件约1000个收件人,所以如果您需要将其分成多个电子邮件将是明智之举。 指的是当你带入诸如 delayed_job resque 宝石之类的东西来处理它。



哦,顺便说一句,你仍然需要为这封电子邮件指定一个地址使邮件宝石高兴。我们有 info@ourcompany.com


$ b SendGrid API也会在电子邮件中支持过滤器,所以您可以使用占位符字符串,如 {{firstname}} ,假设您使用SMTPAPI标头发送它,它将在电子邮件上执行邮件合并并自定义他们。



如果您阅读SendGrid API文档,它会为您带来很多好处。它非常有用,它们提供的功能超强。


I will be sending bulk emails from a Rails app and plan on using SendGrid. I am assuming that it is best to send a separate email to each recipient (as opposed to using BCC for all the recipients). If that is true, should I be using something like DelayedJob to queue the messages going over to SendGrid, or would it be safe to throw 500 messages at it all at once? Thanks!

解决方案

500 messages really isn't that much to SendGrid. It's not even a blip on their radar. I worked for a company that sent out 2.7 million emails in a single month, and even then it's only just a blip.

With the SendGrid API's capabilities, you wouldn't be sending out 500 emails, you would send one email which has a specific SendGrid API header set. Why? Because have you ever tried to send 500 individual email messages and timed how long that takes? How about a single email? The single email's going to be quicker.

The SendGrid API has a Ruby example which is here: https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/ruby.html.

That's quite long winded and messy, so let me simplify it for you. Basically, you set this in your email:

headers["X-SMTPAPI"] = { :to => array_of_recipients }.to_json

SendGrid will then parse this and then send that one email you sent it out to that array of recipients. I seem to recall that they ask you to limit this to about 1000 recipients per email, so it would be wise to split it up over multiple emails if you wanted that. That is when you would bring in something like the delayed_job or resque gems to deal with it.

Oh, and by the way you'll still need to specify a to address for this email just to make the Mail gem happy. We had info@ourcompany.com for that.

The SendGrid API will also support filters in their emails, so you can have placeholder strings such as {{ firstname }} and, assuming you send it through with the SMTPAPI header, it will do the "mail merge" on the email and customize them.

It would do you a great deal of good if you read the SendGrid API documentation. It's really useful and what they provide is super powerful.

这篇关于将电子邮件发送给大量收件人的最佳做法(Rails + SendGrid)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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