Sending out 20,000+ emails with asp.net

2019-03-27 21:31发布

I am writing an application that will need to send a massive amount of emails to our students who will be selected from our database (each email will be personalized to the extent that will include their name, course of study etc...so needs to be sent one at a time).

I could do this looping over an SmtpClient, but I'm afraid that with the numbers I'm trying to send, I'll ultimately run into timeout issues or my thread being killed because of lack of machine resources.

At this point I'm just looking for suggestions of a better way to handle this, or if looping over SmtpClient is an ok solution, how I should go about handling it to prevent what I posted above.

Would a web service be a better alternative?

Please advise, TIA

5条回答
成全新的幸福
2楼-- · 2019-03-27 22:03

You don't need a web service, but rather a way to batch the emails into a queue (perhaps an "Email_Queue" table in the DB). Then a Windows service running on a server could read through the queue in a first-in/first-out basis at reasonable chunks at a time being sent to the SMTPClient, removing items from the queue as they are processed. You would probably need to run some measurements to determine what the chunk size and delay would be for your mail server.

查看更多
Fickle 薄情
3楼-- · 2019-03-27 22:10

You could use javascript on a timer to request the script which sends mail in small chunks that wont time out. Then you'd call the script from the browser. Add a progress bar, authentication, etc.

查看更多
▲ chillily
4楼-- · 2019-03-27 22:12

What about using Database Mail tool provided by SQL Server itself. You can still use asp.net but Email will be sent by SQL Server and all you have to do call the stored procedure and leave things to SQL Server.

I wouldn't recommend batch option since there won't be any optimization or queue thing unless you have to put a lot of effort to do so.

Database Mail tool provides queue and priority options as well. If a problem occurs, the e-mail will be queued again and sent later but the other ones will be still being sent.

It is called Database Mail in SQL Server 2008 and SQL Mail in previous versions.

For more information, please check the links below :

查看更多
孤傲高冷的网名
5楼-- · 2019-03-27 22:13

Ok, first - this is hardly massive, I have been handling 50.000 emails+

Let the emails be written to a FOLDER - directory. Then use the local SMTP service you can install, pointing it at the folder as pickup directory. This will at least make sure you have a decent buffer in between (i.e. you can finish the asp.net side, while the emails are not sent at that point).

查看更多
The star\"
6楼-- · 2019-03-27 22:14

My suggestion would be to batch this out. Do not try to run ASP.NET code to create 20K emails and send them out as you are bound to runinto timeout and performance issues. Instead populate a table with recipient, subject, body and begin a batch process from a windows service. This way your code is executed in a way where lag can be managed, instead of having a web page wait for the request to return.

查看更多
登录 后发表回答