【发布时间】:2012-05-15 02:22:15
【问题描述】:
我已经设置了 SmtpClient 类的 Timeout 属性,但它似乎不起作用,当我给它一个 1 毫秒的值时,执行代码时的超时实际上是 15 秒。我从msdn获取的代码。
string to = "jane@contoso.com";
string from = "ben@contoso.com";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("1.2.3.4");
Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
client.Timeout = 1;
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
我在单声道上尝试了实现,它也不起作用。
有人遇到过同样的问题吗?
【问题讨论】: