ASP.Net MVC后台线程的电子邮件创建和发送 [英] ASP.Net MVC background threads for email creation and sending

查看:108
本文介绍了ASP.Net MVC后台线程的电子邮件创建和发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看postmarkapp.com处理使用.NET库,它们提供了2个应用程序,从我的asp.net mvc的电子邮件的发送:邮戳,DOTNET库

I'm looking at postmarkapp.com to handle the sending of email from my asp.net mvc 2 application using the .net library that they provide: postmark-dotnet library

在他们的文档他们提到发送电子邮件瓦特/附件可能需要一些时间,它能够更好地做到这一点在后台作业。对于我的应用程序可以在任何地方从10到500个性化的电子邮件一些带有附件的成批发送到我的用户。

In their documentation they mention that sending emails w/ attachments can take some time and its better to do this in a background job. For my application I could be sending anywhere from 10 to 500 personalized emails some with attachments in a batch to my users.


  • 什么是非阻塞的方式来发起的创建和在A​​SP.Net MVC?

  • What is the best way to do this background processing in a non blocking way to the admin user that initiated the creation and sending of these emails in ASP.Net MVC?

如果他们点击创建和发送电子邮件500个用户,并关闭了浏览器之前该过程完成后会发生什么?

What happens if they click "create and send emails" to 500 users and close out the browser before that process is complete?

任何帮助的感谢!新来ASP.Net MVC

Thanks for any help! New to ASP.Net MVC

推荐答案

您可以生成一个新的线程,该线程中发送邮件:

You could spawn a new thread and send the mails in this thread:

[HttpPost]
[Authorize(Roles = "Administrator")]
public ActionResult SendMails()
{
    new Thread(() => 
    {
        // Send the emails here
    }).Start();
    return View();
}

如果用户关闭浏览器,直到它完成或在AppDomain将关闭该线程将继续运行。该行动将立即返回一个视图,也不会封锁。

If the user closes the browser this thread will continue running until it completes or the AppDomain shuts down. The action will return a view immediately and it won't block.

此外,它可能是一个好主意,设置一些标志成发送邮件的操作正在运行的数据库,因此,如果管理员单击两次按钮,你的用户没有得到有很多邮件的重创。

Also it could be a good idea to set some flag into the database that an operation of sending emails is running so that if the administrator clicks twice on the button your users don't get hammered with lots of mails.

如果您想了解更多强大的解决方案,你可以看看 MSMQ 。和这里有一个教程,应该让你快速上手。

If you want more robust solution you could take a look at MSMQ. And here's a tutorial that should get you started quickly.

这篇关于ASP.Net MVC后台线程的电子邮件创建和发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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