Question

I've written a contact management/communication system that records the details of people and allows for mass communications to be sent out.

However sometimes when e-mails are being sent the following exception is raised:

System.Threading.ThreadAbortException: Thread was being aborted

What is the best way to send out mass e-mails through ASP.NET?

What I'm looking for is an approach that'll keep it all in ASP.NET

I have a feeling I may need to store the e-mails in a database and have a separate .net console application/Windows Service send them out. However because of the extra development overhead and the lack of time I have, this is the last option I want to consider.

Was it helpful?

Solution

There is no reliable way to do mass email broadcasting from .net without some intermediary.

What I mean by this is that the emails must be queued in your database or other persisted storage. Then, you need another app (console, service, whatever) that is responsible for monitoring the queue and acting on the broadcast requests.

Second, do not send them straight from your code. Instead, send the emails to a local mail server under your control for rebroadcasting to the actual recipient. The shear number of spam detection mechanisms (like grey-listing) means that you will spend an inordinate amount of time doing things sending the message, getting a grey-list denial, waiting 15 minutes (or however long), then sending again to see it go through.

The reason for queueing even if you are going through a real mail server is to keep from overloading your local mail server.

Sending mail from .net is generally fine for those one offs, especially when all of the recipients are within your company. However, anytime you have to send them to the general public with any reliability then you need to "grow up" so to speak.

OTHER TIPS

Have a look at service broker and then have a separate application pull from the queue to fire off the email.

Don't. ASP.net requests can be terminated by IIS if they exceed the timeout, IIS shuts them down, etc.

In this case when you want to send the emails, you want to spawn an external process that can do it, because that can run for however long is required. You could write a small little executable console app that knows how to send them, and have your web page run it as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top