Sending a large number of emails using SmtpClient (C #) takes a very long time later

I use this piece of code to send mail:

SmtpClient client = new SmtpClient();
client.Host = smtpServer;
client.Send(mailMessage);

If I run this code ten times / second, then after several hundred letters sending mail will take 10 seconds ... Maybe there is a queue here?

  • Shouldn't it be asynchronous?
+5
source share
3 answers

Use SmtpClient.SendAsync, not SmtpClient.Send.

+2
source

There may be several problems:

Are you managing your MailMessage objects correctly? If you look, the object implements IDisposable and therefore must be deleted. (I would suggest because of potential investments.) I would start here.

. - , , .

, SendCompleted. , , , SendCompleted. , , , , .

+2

Can a mail server manage your requests? I send mail using the local IIS SMTP server, and sending mail takes very little time for .NET, even when I have thousands of messages sent in a few minutes (exception handler is wrong: P), but they can be processed very slowly IIS and can sometimes take hours to clear the IIS message queue

+1
source

All Articles