批量发送通知邮件而不阻塞

发布于 2024-10-11 16:48:39 字数 347 浏览 5 评论 0原文

对于我客户的定制 CRM,我希望通过电子邮件向用户(技术人员)通知标记案例的更改。

这保证了用户和案例之间有一个简单的订阅映射表,并且每次在日志记录方法中对案例进行更改时都会发送自动电子邮件。

如何在不影响我的日志记录方法的情况下向订阅用户发送 10-100 封电子邮件?我的 SMTP 服务器位于 LAN 上的对等点上,因此发送应该很快,但理想情况下这应该由外部排队进程处理。

我可以让 cron 作业每 10 分钟发送一次未完成的电子邮件,但对于这个特定的客户案例来说,时间非常敏感,即时通知(与电子邮件一样即时)会很棒。

如何从 ASP.NET MVC 中发送批量通知电子邮件而不会使我的日志记录方法陷入困境?

For my client's custom-built CRM, I want users (technicians) to be notified of changes to marked cases via email.

This warrants a simple subscription mapping table between users and cases and automated emails to be sent every time a change is made to a case from within the logging method.

How do I send 10-100 emails to subscribed users without bogging down my logging method? My SMTP server is on a peer on my LAN, so sends should be quick, but ideally this should be handled by an external queuing process.

I can have a cron job send any outstanding emails every 10 minutes, but for this specific client cases are quite time-sensitive and instant notification (as instant as email can be) would be great.

How can I send bulk notification emails from within ASP.NET MVC without bogging down my logging method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落□心尘 2024-10-18 16:48:39

早在 2007 年,我就被要求调查一个案例,其中 Web 服务器会突然冻结并开始发送 503 错误,并在几分钟后返回。长话短说,最后发现它发送的电子邮件阻塞了服务器(除了一些错误的代码)。

基本上,Microsoft 的 SMTP 服务器是作为单线程服务实现的 - 我上次检查过。这意味着服务请求的所有有价值的 ASP.NET 线程都必须排队到单线程整体应用程序才能发送不太紧急的电子邮件。您需要将您的网站与发送电子邮件分离 - 这是每个人都会做的事情,并且有一个很好的理由。

将电子邮件写入队列,并有一个进程读取和发送电子邮件。

Back in 2007 I was asked to look into a case where Web Server would suddenly freeze and start sending 503 errors and come back after a few minutes. Cutting a long story short it turned out at the end that it was sending email which was blocking the server (in addition to some bad code).

Basically Microsoft's SMTP server is implemented as a single-thread service - last I checked. This will mean that all your valuable ASP.NET threads serving requests will have to queue to a single thread monolithic application to send a not so urgent email. You need to decouple your web site from sending emails - that is what everyone does and there is a good reason for it.

Write your emails to a queue and have a process reading and sending emails.

横笛休吹塞上声 2024-10-18 16:48:39

从 ASP.NET 应用程序发送电子邮件不是一个好主意,因为它可能会独占宝贵的服务器资源。更好的解决方案是设置一个 Windows 服务来执行此任务,甚至编写一个可以安排与 Windows Scheduler 一起运行的控制台应用程序。 Quartz.NET 是一个很好的解决方案,您可以考虑一下,它允许您安排作业。

如果您希望从特定控制器操作中触发这些电子邮件发送,您还可以拥有一个可以异步调用的单独的 WCF 服务。

Sending emails from an ASP.NET application is not a good idea as it might monopolize valuable server resources. A better solution would be to setup a Windows Service to perform this task or even write a Console application which could be scheduled to run with Windows Scheduler. Quartz.NET is a good solution you might take a look at allowing you to schedule jobs.

If you want those email sending to be triggered from within a particular controller action you could also have a separate WCF service which could be invoked asynchronously.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文