views:

51

answers:

3

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?

A: 

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.

Tom Cabanski
A: 

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

C Bauer
+1  A: 

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! =)

Pedro MM