Reputation: 496
I have an ASP.NET MVC Web Application in C#. I want to send bulk emails with attachments without any delay. I use Microsoft.Exchange.WebServices to send email using an exchange server. Everything works fine but even for sending 2 emails with 1 MB attachments takes about 30-45 seconds of time. I have use cases of sending 2000 emails too so I know its going to crash the server.
Requirement: As soon as I click send in my UI, it should prompt the user saying the emails are being sent and the user can continue to browse.
Is there any asynchronous way to send bulk emails in ASP.NET C# using EWS? I googled and found couple options which I haven't implemented yet but I have few questions:
Can I use Delegates to do the task asynchronously? What will happen if a user exits the application. Will it finish sending emails or stop?
Can I use System.Threading.ThreadPool.QueueUserWorkItem? What will happen if a user exits the application. Will it finish sending emails or stop?
In the past I have used MSMQ to accomplish this task but we do not have time to implement the whole mechanism including listeners.
Upvotes: 2
Views: 797
Reputation: 22032
Why do you need to use EWS? SMTP would be a better choice for sending mail in volume, the transport service on the Exchange server will handle and queue the messages where necessary if they aren't destined for internal users it will then send them on to their external sources. Using EWS means the Exchange Store will be processing the messages and you be potentially throttled if throttling is enabled which should stop you affecting the server too badly but would slow the process down. Using SMTP would avoid any impact on the end users using Outlook (with some proviso if the server is multi rolled and your application doesn't end up essentially DOS's your own server) however may impact on the message flow in and out of you org depending on the how much email your sending as it will need to process the Message in the queues.
Upvotes: 2