Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending lots of mails using SmtpClient (C#) takes very long after a while

Tags:

c#

.net

smtp

I'm using this piece of code to send a mail:

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

If I trigger this code ten times/second, then after some hundred mails, sending a mail takes 10 seconds... Could there be a queue involved here?

  • Shouldn't this be asynchronous?
like image 226
Lieven Cardoen Avatar asked Apr 18 '10 12:04

Lieven Cardoen


People also ask

Is SmtpClient obsolete?

The SmtpClient class is obsolete in Xamarin. However: It is included in the . NET Standard 2.0 and later versions and therefore must be part of any .

Can we send multiple mails using SMTP?

By default, a single SMTP transport creates a single connection and re-uses it for the lifetime of the script execution. You may send multiple e-mails through this SMTP connection. A RSET command is issued before each delivery to ensure the correct SMTP handshake is followed.

How send email to multiple recipients in MVC?

Add(new MailAddress(ccEmail)); Msg. Bcc. Add(new MailAddress(bccEmail)); } SmtpClient a = new SmtpClient("smtp server name"); a. Send(Msg); sreader.

What is my SMTP host?

You can generally find your SMTP email server address in the account or settings section of your mail client. When you send an email, with SMTP host Gmail or AOL, the SMTP server processes your email, decides which server to send the message to, and relays the message to that server.


1 Answers

Use SmtpClient.SendAsync rather than SmtpClient.Send.

like image 138
Hans Olsson Avatar answered Sep 28 '22 18:09

Hans Olsson