我已经设置了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);
我在mono上尝试了这个实现,但它也没有起作用。
有人遇到了同样的问题吗?