I know how to write the basic c# code to send emails, but I'm wondering about any larger issues involved. Are there things I should avoid? Best practices? etc
Thanks!!
I know how to write the basic c# code to send emails, but I'm wondering about any larger issues involved. Are there things I should avoid? Best practices? etc
Thanks!!
You shoul probably throttle your emails to not send more that x per unit time. You do not want a client's email server to mistake your emails for a denial of service attack.
I assume you have dealt with the larger isues like how a client opt-in or unsubscribes?
Also be prepaired for a lot of messages coming back as undeliverable, and be prepaired to process them. People change their email address all the time, leave a company etc. Do not make an enemy of a client (or large ISP) by continuing to send email to the same undeliverable addresses day after day.
In response to your comment, a powerful email server on a fast connection could easily send 100s if not 1,000s of emails per second.
Give some thought to what time of day you want the reciepient to actually get the email. Morning, afternoon etc. And think in terms of his (not yours) time zone. An email promoting a "ideal wine for dinner" would be better sent at 4 PM than 4 AM.
Be extremely careful of using a "shared" email server. Are you sharing it with a spammer who will get the ip address blacklisted? How can you be sure that will not change tomorrow?
Are you familiar with the Trusted Email Open Standard? The more you can do to seperate yourself from the spammers, the better your email campain will be received.
You probably want to spawn this stuff out in batches, so everything is not being sent from one process in a continuous loop. You can do this much quicker if you group the batches by 25 e-mails and spawn say 50 threads to send those 25 queues. Given your 10,000 e-mails it would only take 8 loops to complete the whole batch of e-mails.
You can obviously change these numbers, but you will need to split this up in to multiple threads that send a group of e-mail. It will be up to you to find the optimal numbers of this process.
This doesn't really have anything to do with .net, but:
Create an easy method for unsubscribing.
Make sure your host's IP address isn't already listed on a blacklist. Also, make sure the reverse DNS is configured correctly.
Make sure you store your configuration in a configuration file. It will make your life easier.
Web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections >
</configSections >
<system.net>
<mailSettings>
<smtp from="[email protected]" deliveryMethod="Network">
<network host="smtp.gmail.com" port="587" userName="[email protected]" password="password" />
</smtp>
</mailSettings>
</system.net>
</configuration>
If you're going to be sending out thousands of emails, I'm assuming you're going to be part of some corporate entity doing it. This is less a response on how, but you really need to be aware of the CAN SPAM Act of 2003. My company does mass-emailing and it was one of the first things I got handed on my first day of the job. Given that it can provide some rather steep penalties, ensuring that you're abiding by the stipulations of the act can help avoid some issues.
I would seriously consider hosting your mail server somewhere else.
Spamhous, Outblaze, and others, have already blacklisted most of the EC2 address space. You're going to have a hard time with it.
See http://voices.washingtonpost.com/securityfix/2008/07/amazon_hey_spammers_get_off_my.html and http://www.webhostingtalk.com/showthread.php?t=856428
UPDATE for recommendations
If I was to go down this route I would do one of two things. Either I would build my own mail server and stay on top of the blacklists; or, I would integrate with an email marketing company like Constant Contact. They have a pretty decent web services API.
At GameSpy, we used MSMQ for Queuing our emails, sometimes a hundred thousand or more. If the service crashed or something went wrong it was easy enough to restart and it resumed where it left off.
Be very cautious about how you're threading the thing. I've seen some bad code that would launch several threads but have no way of putting a lock on the data, causing some people to get as many as ten or more of the same e-mail. That's obviously not good.
Also, if it has to run on the same box as your Web site, you definitely want to use some kind of Timer object to not send everything at once. You could bring the CPU or disk to its knees depending on your implementation.
I worked on a bulk email system for a marketing company. We sent about 10 million a month between several clients. A few pointers: