Why can SmtpClient.SendAsync only be called once?

Daniel picture Daniel · Dec 23, 2008 · Viewed 15.1k times · Source

I'm trying to write a notification service (for completely legit non-spam purposes) in .NET using SmtpClient. Initially I just looped through each message and sent it, however this is slow and I would like to improve the speed. So, I switched to using 'SendAsync', but now get the following error on the second call:

An asynchronous call is already in progress. 

I read this to mean that MS crippled System.Net.Mail to prevent mass-mailers. Is this correct? If so, is there a better way to do this in .NET, and still be able to log the results of each email(which is important to our client). If not, why can SendAsync only be called once?

Answer

Darin Dimitrov picture Darin Dimitrov · Dec 23, 2008

According to the documentation:

After calling SendAsync, you must wait for the e-mail transmission to complete before attempting to send another e-mail message using Send or SendAsync.

So to send multiple mails at the same time you need multiple SmtpClient instances.