如何从ASP.NET发送大量电子邮件? [英] How do you send mass emails from ASP.NET?

查看:134
本文介绍了如何从ASP.NET发送大量电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建了一个网站,客户端,他们希望自定义的通讯工具。构建工具很容易,但我不知道如何发送电子邮件。

I built a website for a client and they would like a custom newsletter tool. Building the tool was easy, but I'm not sure how to send the email.

我成立了一个测试页面,管理使用System.Net.Mail命名空间来发送测试电子邮件给自己。我试图将这种code电子报页面上的循环,但它的转向了是一个相当艰巨的任务。电子邮件发送环路锁定了整幅约一小时,而它发送其电子邮件。有时它会中止循环中途以及一些电子邮件不会被发送。

I set up a test page and managed to send a test email to myself using the System.Net.Mail namespace. I tried applying this code to a loop on the newsletter page, but it's turning out to be quite a difficult task. The email sending loop locks up the whole site for about an hour while it sends its emails. Sometimes it will abort the loop midway and some of the emails won't get sent.

我试着开始在另一个线程的回路。

I tried starting the loop on another thread.

protected void btnSendNewsletter_Click(object sender, EventArgs e)
{
    Thread t = new System.Threading.Thread(new ThreadStart(SendEmails));
    t.Start();
}

但仍使得网站走的慢,也有通过中止中途的习惯。什么是发送大量电子邮件的常用方法?我敢肯定,我不这样做是正确的。

but this still makes the site go slow and also has a habit of aborting part way through. What is the common method for sending mass emails? I'm sure I'm not doing it right.

我很新的.NET中的电子邮件竞技场因此任何帮助是非常AP preciated。

I am very new to the email arena in .NET so any help is much appreciated.

推荐答案

有关这样的任务,你最好一堆作业添加到队列中。然后有一个线程运行该拉作业x个从队列,处理这些(即发送的电子邮件),然后睡了一段时间。这会给你的web应用程序的一些喘息的空间。

For this kind of task you're better to add a bunch of jobs to a queue. Then have a thread running which pulls x number of jobs from the queue, processes them (i.e. sends the emails) and then sleeps for a period of time. This will give you web app some breathing space.

如果你使用你可以创建一个邮件队列表来存储作业的数据库。我preFER柜面应用回收出于某种原因或抛出一个异常使用这种存储过的记忆... ATLEAST你可以再从你离开的地方接了。

If you're using a database you can create an Email Queue table to store the jobs. I prefer to use this kind of storage over memory incase the app recycles for some reason or an exception is thrown...atleast you can then pick up from where you left off.

通常情况下,在运行工作线程的过程不会是web应用程序本身。这将是一个Windows服务或类似的东西。如果你是共享主机,这可能是不可能的。

Generally, the process running the worker thread wouldn't be the web app itself. It would be a windows service or something similar. This might not be possible if you're on shared hosting.

这篇关于如何从ASP.NET发送大量电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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