How de we send out 5000 emails per hour using actionmailer in ruby on rails?

爱⌒轻易说出口 提交于 2019-12-17 19:03:48

问题


I have some questions about ActionMailer :

  1. How does Actionmailer connect to a smtp server ?

  2. Are the connections concurrent or parallel if the number of emails high > 1000 ?

  3. How will sending out emails like facebook does ( 1000's in numbers ) as immediate emails affect the ruby on rails application and how would actionmailer handle it ?

  4. Any other solution/plugin to send out large number emails from a RoR application apart ActionMailer?

------------------------------------------------added :

We need to send out at least 1000 emails per 15 minutes . We are using a Notes Domino server as our smtp server .! what is the possible architecture for this kind of problem. We are already storing the emails in the database to send them later , but what is needed is the sending approach !


回答1:


The usual thing is to create a background job to send email. ActionMailer is very good for single emails but does tend to run into trouble after sending multiple emails as each one can take several seconds to complete. That's why I created PostageApp to help solve those problems.

Some services on the market to help you with sending lots of email from Rails:

  • MailGun
  • SendGrid
  • PostmarkApp
  • MailChimp
  • Mailjet
  • PostageApp

All of these have ways of sending multiple messages with a single API call or SMTP transaction.




回答2:


1) Actionmailer connects to your smtp server via a set of parameters including a host, port and protocol.

3) The effect will be a slow site as a result of the many synchronous tasks being executed.

2 & 4)

Actionmailer is a bit too slow to be sending out a ton of emails under load, remember that it is a synchronous operation and as such its not really the sort of thing you want to be doing a lot on a busy site.

To be honest you're better off not sending that quantity of email from your website. It's not really designed to be used in such a way. If I had to send that sort of volume I'd look at doing the work in the background, something like Delayed Job would work well here or one of the many async rails mailers found here would do the trick.

What you really want to look at here is the requirement that you're trying to fulfil, is it absolutely necessary that the website be responsible for sending the mail in a synchronous fashion? In most cases the answer to that question is no. If you can, you'll be far better off deferring this sort of task to another part of your system, keep your site as lean and focused as you can.




回答3:


Simple solution here for you... Sidekiq or Resque

I'd highly recommend Sidekiq as it's not near as server intense for running multiple workers for this one - only be careful with concurrency issues (make sure you don't have 2 workers pick up the same job and send duplicate emails that is).

Say you set 20 Sidekiq workers, each should be able to send an email every 2-4 seconds, you're looking at an easy 300-600 per minute.

DO NOT try to do this without background workers like Sidekiq, Resque, or DelayedJob. You will freeze your entire app if you try sending in app with any large amount of emails. Even sending activation emails in app and what not will cause you unnecessary slow down issues.

I'd have one Worker that handles the queueing periodically and another Worker class that handles the sending. We're using Resque (6 workers maybe?) for this on an older app (pre-sidekiq) to send around 500 emails every 5 minutes with no issues.

You can aways use a third party like someone mentioned. Sendgrid is decent. But that wasn't the question, this is how you do it yourself simply and easily.




回答4:


  1. You define the SMTP settings in a config file if left blank it uses sendMail local

  2. concurrent

  3. multiple handlers

  4. Is there a bulk email plugin for Rails apps?

you may also do 1000.times do email.deliver but it will probably collapse ur server



来源:https://stackoverflow.com/questions/10125663/how-de-we-send-out-5000-emails-per-hour-using-actionmailer-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!