Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to send emails to 50,000 customers through my windows application below is the details of my task.

1) I am pulling all customers and dividing the total customers into 10 threads.
2) then each threads is assigned some customers so for each customers i am generating the crystal report and exporting it to PDF and then sending an email to customer.

As the list of customers are 500000 its taking 8 hours to complete the task. Customers will increase in future and then it will take more time.

Can some one suggest the best possible way to accomplish this task within 3 hours.
Posted
Comments
F-ES Sitecore 3-Feb-16 5:18am    
What is the bottleneck? The generating of the files or the sending of the emails? Any solution is likely to involve scaling out and running the process on multiple machines, or on a machine with more cores\processors. If they're all going through the same smtp server then that'll be a bottleneck too so maybe use multiple mail servers or use a company that specialises in bulk mailing.
EliteBrain 3-Feb-16 8:52am    
We are using a MS exchange server which i believe can send 3-4 emails/sec. We dont have any infrastructure limitation.. I am only confirm about the best way to design the bulk emailer with PDF attachment.
Sinisa Hajnal 3-Feb-16 6:19am    
Pay for newsletter services or you'll end up either sending the mails with delays to avoid being listed as spammer or you'll get onto blacklists and your e-mails will be rejected by spam filters all over the world.

As for optimisation: set more threads to creating reports and PDF converting in advance. Have sending only grab the file and send it. No conversion, no nothing. It should be already be ready for sending.
Philippe Mori 3-Feb-16 13:02pm    
If it take 8 hours to email to 500 000 users, then for 50 000 user, it should take about 48 minutes which is far less than 3 hours. Problem solved! Basic maths...

You cannot do anything to increase that speed! Not because there is not a better solution, but because the process relies on the network resources too. Your internet bandwidth is going to play a very vital role in sending the emails through a remote SMTP server.

Typically, sending one email from a desktop application takes ~2 seconds (You can try that out yourself but sending one email to your own email address using an SMTP server; Sending emails over .NET framework, and general problems – using C# code[^]). So what is going to happen is that you are going to multiply 2 seconds (of average) with 50,000 clients.

There are many ways around this:

1. Consider increasing the bandwidth of your network connection.
2. Use the best possible way to iterate over the collection.
3. Do not generate the PDF again and again, use caching for this.

So on. But, basically, the thing boils down to saying, for such an action you are going to use a service from a third-party company who send the emails on your behalf to 50,000 clients using an email message, an email attachment and so on. Why? Because it would cost you a lot of money to upgrade the systems just to make the email sending process easy.
 
Share this answer
 
Comments
EliteBrain 3-Feb-16 9:02am    
Thanks afzaal for you valuable time.keeping in mind the points which you have mentioned I will go through some more article on multithreading to solve this issue.
What do you think does parallel.Foreach loop will help me in this?
Afzaal Ahmad Zeeshan 3-Feb-16 9:18am    
No, because after all, that would just create a sense of responsibility in your application but there won't be any upgrade in the performance of the network. Suppose, you can now turn down the total time required to execute the function for smtpClient.Send() by approximately, 1 milliseconds. But the time required by network would still be 4 seconds. That won't help you at all.

You can however, minimize the side-effects in the code. You can remove the regeneration of the objects. Try to cache the PDF and the string for the email message. That would give you a better performance or a speed up on the function calls.

Network based delay is still a common delay.
Your best solution is to use an outside bulk mail service for this. No amount of threading is going to help you and if you've only got one, or ust a few, email servers in your company that's your limitation. There is no getting around that unless you stand up more servers.

Google for "Bulk email service provider".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900