开发者

Bulk mailing using SMTP server in ASP.Net

We are sending free newsletters to all users who have registered for this service. Since these newsletters are sent free of cost we expect at least 5000 subscribers within a month. I am worried whether bulk mailing using SMTP server concept will cause some issue. First we thought of developing a windows service which would automatically mail to subscribers on periodical basis but the business users have given requirement that the newsletters should be editable by the admin and then only mailed to users so we had to develop this functionality in website itself!. I get the subscribers for the particular user in data table and then mail to each user inside for loop, will this cause any performance issue? The code is pasted below:

dsEmailds.Tables[0] has list of newsletter subscribers.

for (iCnt = 0; iCnt < dsEmailIds.Tables[0].Rows.Count; iCnt++)
{
    MailMessage msg = new MailMessage();
    msg.From = new MailAddress("newsletters@domainname.com", "test1");
    msg.To.Add(dsEmailIds.Tables[0].Rows[iCnt]["mailid"]);
    msg.IsBodyHtml = 开发者_StackOverflow社区true;
    msg.Subject = subject;
    AlternateView av1 = AlternateView.CreateAlternateViewFromString(MailMsg, null, System.Net.Mime.MediaTypeNames.Text.Html);
        av1.LinkedResources.Add(lnkResLogo);
        av1.LinkedResources.Add(lnkResSalesProperty);
        av1.LinkedResources.Add(lnkResLeaseProperty);
        msg.AlternateViews.Add(av1);

SmtpClient objSMTPClient = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["mailserver"].ToString());
objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSMTPClient.Send(msg);
}         

Any suggestions would be great!


You should STOP and consider all sort of things:

  • Black List: with that amount you will for sure be balck listed in severeal ISP's / Mail Servers, and you need to prove that the received user asked for such email and wait 1 to 3 month process while they remove the flag

  • You need to send emails in blocks, not more than 250 at each time, use different IP's machines to send more emails (more blocks)

please read some nice guidelines for doing all this, you can find it in MailChimp and Campaign Monitor

Free Email Marketing Guides

You should use a service, like Mailchimp (now it's free to 1000 subscribes, 3000 sends a month) but prices are very cheap and they have an API that you can easily add, create, send and you will get all those nice reports on how opened, what did they do, etc ...

Campaign Monitor is fantastic as well, but a little bit more expensive but great as you can brand the entire UI and sell as a service to your customers (if you are thinking of doing such thing in the near future).

I hope it helps.

give them a try, I'm a happy customer.


The main problem i see is that you may encounter a page timeout. The best way to do it in my opinion would be to set up a service that will take care of mail-related uses (templating for example) by reading from a queue. Your website could just post the mails you expect to send in the queue, then offer a basic administration panel to manage the service and get some stats.

You can use open-source & xcopy-friendly systems for the queue like Rhino queue, or ServiceBus, and Topshelf for services if you want easy setup

But i'd recommend you not to send bulk emails in the webpage


There is a SendAsync method that will actually queue up these requests and send them async from your thread. This way you can prevent the timeout and you can probably send (ie. queue) 5000 emails within seconds.


  • Write to a pickup queue of an SMTP server running on the machine (IIS includes one). This is the fastest and most efficient method.

OR

  • Setup a custom thread pool in your code and offload the task to it. That way worker threads from ASP.NET thread pool are ready to serve incoming requests and won't be occupied with sending mails (that depends on how high your server load is, of course - go ahead with ASP.NET thread pool using async methods if you don't care about the load/can afford it).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜