Kumar
Kumar

Reputation: 2863

smtp.Send() Issue

I building a web application in ASP.NET 3.5 and C#. I have a method in my project which sends emails to the users. But for some reason the smtp send method is taking 3 to 4 seconds to execute:

 SmtpClient smtp = new SmtpClient();
 smtp.Send(msg);-----> This is the line of code which takes 3 to 4 seconds to execute

What could be the reasons behind this delay?

Upvotes: 0

Views: 175

Answers (3)

pmmaga
pmmaga

Reputation: 410

You can always use the .SendAsync() method. This way, it will send the smtp request and won't wait for it's response! If you don't need the bool output of the .Send() method, problem solved! =)

Upvotes: 1

C Bauer
C Bauer

Reputation: 5103

Could be poor connectivity between your SMTP server and your local machine.

Upvotes: 0

Tom Cabanski
Tom Cabanski

Reputation: 8018

The send method is making a call to your email server to queue the mail. Network latency and the performance of the mail server are going to impact how long this takes. That's why many application do this kind of thing on a background thread or via some sort of internal, reliable work queue mechanism.

Upvotes: 0

Related Questions