How to implement a mailing system with Rails that sends emails in the background

僤鯓⒐⒋嵵緔 提交于 2019-12-09 14:05:25

问题


I want to implement a reliable mailing system with Ruby on Rails that sends emails in the background as sending email sometimes takes like 10 seconds or more so I don't want the user to wait. Some ideas I thought of:

  1. Write to a table in DB a have a background process that go over and send email (concern: potential many reads/writes to DB slows down my application)

  2. Messaging Queue background process / Rake task (concern: if server crashes queued mails will be lost also might eat up a lot of memory if many emails)

I was wondering if you a know of a good solution that provides a balance between reliability and performance.


回答1:


I think Starling and Workling will be able to assist you =) Watch this railscast: http://railscasts.com/episodes/128-starling-and-workling




回答2:


You can implement the feature or rely on external services.

I have been using PostageApp for the last 2 months and I'm really happy with it. An other solution is Postmark.

Otherwise, if you want to code it, first you need a queue system. For Rails, you can use DelayedJob or Resque. Sending emails in the background is probably the most simple solution, the "problem" is dealing with failures and retry.




回答3:


Have you looked at the mail-queue plugin?

http://code.google.com/p/mail-queue/

The docs seem to suggest it stores the mails in a DB table, thus avoiding #2 at least.



来源:https://stackoverflow.com/questions/2665920/how-to-implement-a-mailing-system-with-rails-that-sends-emails-in-the-background

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