简体   繁体   English

用于向 Web 应用程序的所有用户发送邮件的框架或设计模式

[英]Framework or design pattern for mailing all users of a webapp

My app takes care of user registration (with the option to receive email announcements), and can easily handle the actual template-based rendering of email for a given user.我的应用程序负责用户注册(可以选择接收 email 公告),并且可以轻松处理给定用户的 email 的实际基于模板的呈现。 JavaMail provides the mail transport layer. JavaMail 提供邮件传输层。 But how should I design the application layer between the business objects (eg User) and the mail transport?但是我应该如何设计业务对象(例如用户)和邮件传输之间的应用层呢?

The straightforward approach would be a simple, synchronous loop: iterate through the users, queue the emails, and be done with it.直接的方法是一个简单的同步循环:遍历用户,将电子邮件排队,然后完成。 "Queue" might mean sending them straight to the MTA (mail server), or to an in-memory queue to be consumed by another thread. “队列”可能意味着将它们直接发送到 MTA(邮件服务器),或发送到内存队列以供另一个线程使用。

However , I also plan to implement features like throttling the rate of emails, processing bounced emails (NDRs), and maintaining status across application restarts.但是,我还计划实施一些功能,例如限制电子邮件速率、处理退回的电子邮件 (NDR) 以及在应用程序重新启动时保持状态。 My intuition is that a good design would decouple this from both the business layer and the mail transport layer as much as possible.我的直觉是,一个好的设计会尽可能地将其与业务层和邮件传输层分离。 I wondered if others had solved this problem before, but after much searching I haven't found any Java libraries which seem to fit this problem.我想知道其他人以前是否解决过这个问题,但经过大量搜索后,我还没有找到任何似乎适合这个问题的 Java 库。 Standalone mail apps such as James or list servers are too large in scope; scope中James或list servers等独立邮件应用过大; packages like Spring's MailSender or Commons Email are too small in scope (being basically drop-in replacements for JavaMail).Spring 的 MailSenderCommons Email这样的包在 scope 中太小了(基本上是 JavaMail 的直接替代品)。 For other languages I haven't found anything appropriate either.对于其他语言,我也没有找到合适的。

I'm curious about how other developers have gone about adding bulk mailing to their applications.我很好奇其他开发人员如何将批量邮件添加到他们的应用程序中。

The approach I've been happiest with is to provide an interface to my application to "send" mails.我最喜欢的方法是为我的应用程序提供一个接口来“发送”邮件。 In reality, the implementation of this interface simply queues the mail into a database for later processing.实际上,此接口的实现只是将邮件排队到数据库中以供以后处理。 From the application's perspective, this interface is fast , as it performs very little actual work.从应用程序的角度来看,此接口速度很快,因为它执行的实际工作很少。 Plus, the persistence survives server downtime, as you mentioned.另外,正如您提到的,持久性在服务器停机后仍然存在。

Another thread reads from the queue and takes it's sweet time sending mail up to it's configured throttle, and flags messages in the queue after successfully processing them (effectively dequeuing them without deleting them).另一个线程从队列中读取并花时间发送邮件直到它配置的限制,并在成功处理后标记队列中的消息(有效地使它们出队而不删除它们)。 This provides both a history of sent mail, and a reference when mail is bounced, etc. I delete from the queue 7 days after a successful send.这既提供了已发送邮件的历史记录,也提供了邮件被退回时的参考等。我在成功发送 7 天后从队列中删除。

In terms of decoupling the solution from the mail transport layer... I've applied this approach to an automated Twitter client, and found it to be equally successful.在将解决方案与邮件传输层解耦方面...我已将此方法应用于自动化 Twitter 客户端,并发现它同样成功。

One option is to use a hardware appliance.一种选择是使用硬件设备。 My company uses Strongmail, at least for marketing communications: http://www.strongmail.com/index.php .我的公司使用 Strongmail,至少用于营销传播: http://www.strongmail.com/index.php I don't know much about it, but I think it handles bulk e-mail concerns like do-not-contact lists, throttling, avoiding getting spam filtered, etc.我对此了解不多,但我认为它可以处理大量电子邮件问题,例如请勿联系列表、节流、避免垃圾邮件过滤等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 针对不同用户的设计模式 - Design Pattern for different users 设计模式-不带DI框架的Webapp - Design patterns - webapp without DI framework 获取Java webapp中的所有用户和角色 - Get all users and roles in Java webapp 如何在Play框架中结合python脚本设计价格检查webapp? - how to design a price checking webapp in play framework combine with python scripting? 方法设计模式 - 强制所有方法遵循一个模式 - Method design pattern - Enforce all methods to follow a pattern 与Selenium对象模式设计的Robot框架关键字管理集成 - Integration with Robot framework's keyword management for Selenium Object Pattern Design Java Executor框架实现了哪些设计模式? - What design pattern does Java Executor framework implements? Spring Framework - 为游戏创建规则引擎的设计模式 - Spring Framework - Design pattern to create a rules engine for game 无法使用 Spring 引导框架区分桥接设计模式中的可注入对象 - Not able to distinguish injectable objects in the Bridge design pattern with Spring boot framework 我应该使用哪种设计模式? 使用Spring框架 - What design pattern should I use ? using spring framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM