简体   繁体   English

smtp.Send()问题

[英]smtp.Send() Issue

I building a web application in ASP.NET 3.5 and C#. 我在ASP.NET 3.5和C#中构建Web应用程序。 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: 但是由于某种原因,smtp send方法需要3到4秒才能执行:

 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? 延迟的原因可能是什么?

You can always use the .SendAsync() method. 您始终可以使用.SendAsync()方法。 This way, it will send the smtp request and won't wait for it's response! 这样,它将发送smtp请求,而不会等待它的响应! If you don't need the bool output of the .Send() method, problem solved! 如果不需要.Send()方法的bool输出,则可以解决问题! =) =)

The send method is making a call to your email server to queue the mail. send方法正在呼叫您的电子邮件服务器以使邮件排队。 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. 这就是为什么许多应用程序在后台线程或通过某种内部可靠的工作队列机制来执行此类操作的原因。

SMTP服务器和本地计算机之间的连接性可能很差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM