2011-07-04 116 views
2

我使用此代码尝试发送电子邮件。几秒钟后,它向我显示一条错误消息,声称操作已超时。我该如何解决这个问题?超时发送邮件时出错

try 
{ 
    MailAddress from = new MailAddress("[email protected]", "name", Encoding.UTF8); 
    MailAddress to = new MailAddress("[email protected]"); 
    MailMessage message = new MailMessage(from, to); 
    message.Subject = "Test"; 
    message.SubjectEncoding = Encoding.UTF8; 
    message.Body = "Test"; 
    message.BodyEncoding = Encoding.UTF8; 
    SmtpClient client = new SmtpClient(); 
    client.Host = "smtp.mail.yahoo.com"; 
    client.Port = 465; 
    client.EnableSsl = true; 
    client.Credentials = new NetworkCredential("[email protected]", "Password"); 
    client.Send(message); 
    MessageBox.Show("sending Successfully!!!"); 
} 
catch (SmtpException ex) 
{ 
    MessageBox.Show(ex.ToString()); 
} 

回答

2

您确定您可以联系到smtp.mail.yahoo.com端口465?听起来很像网络相关的问题。通常,当某些事情超时时,这意味着它试图连接到服务器一段时间,然后停止并给出错误。

一个简单的方法来测试这是telnetsmtp.mail.yahoo.com端口465,看看它是否超时。如果已安装,则可以在窗口中使用Putty或内置的telnet -client。

0

按我的理解,你的代码将无法工作,因为yahoo.com不提供您通过SMTP访问。为此,您需要升级到Yahoo!邮件加

无法找到雅虎任何形式的KB在这。我从Yahoo!获得了这些信息。文章在How to read Yahoo! Mail Plus using Outlook Express。文章的前两行非常相关。

你想阅读和发送您的Yahoo!电子邮件与Outlook Express?
如果您是Yahoo! Mail Plus用户可以。

而且还传出SMTP服务器应该是

client.Host = "plus.smtp.mail.yahoo.com"; 
0

我有同样的问题 你必须设置clietn.port 25,你必须登录指定客户端的密码。证书=新的NetworkCredential(登录名,密码)

当我这样做,我可以发送邮件没有问题

有代码

{ 
SmtpClient client = new SmtpClient("188.125.69.59");//you can put the ip adress or the dns of smtp server (smtp.mail.yahoo.com as exemple) 
       // Specify the e-mail sender. 
       // Create a mailing address that includes a UTF8 character 
       // in the display name. 
       MailAddress from = new MailAddress("[email protected]"); 
       // Set destinations for the e-mail message. 
       MailAddress to = new MailAddress("[email protected]"); 
       // Specify the message content. 
       MailMessage message = new MailMessage(from, to); 
       message.Body = "This is a test e-mail message sent by an application. "; 
       // Include some non-ASCII characters in body and subject. 
       string someArrows = new string(new char[] {'\u2190', '\u2191', '\u2192', '\u2193'}); 
       message.Body ="cc"; 
       message.BodyEncoding = System.Text.Encoding.UTF8; 
       message.Subject = "test message 1"; 
       message.SubjectEncoding = System.Text.Encoding.UTF8; 
       string userState = "test message1"; 
       MessageBox.Show("sending"); 
       client.Port = 25; 
       // client.Timeout = 40000; 
       client.ServicePoint.MaxIdleTime = 1; 
       client.Credentials = new System.Net.NetworkCredential("[email protected]", "pass"); 
       //client.SendAsync(message, userState); 
       client.Send(message); 
       MessageBox.Show("Sending message... press c to cancel mail. Press any other key to exit."); 
       string answer = Console.ReadLine(); 
       // If the user canceled the send, and mail hasn't been sent yet, 
       // then cancel the pending operation. 
       // if (answer.StartsWith("c") && mailSent == false) 
       //{ 
        // client.SendAsyncCancel(); 
       //} 
       // Clean up. 
       message.Dispose(); 
       MessageBox.Show("Goodbye."); 
} 
0

使用以下设置域@yahoo.co.in

var smtp = new System.Net.Mail.SmtpClient(); 
     { 
      smtp.Host ="smtp.mail.yahoo.co.in"; 
      smtp.Port = 25; 
      smtp.EnableSsl = true; 
      smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
      smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); 
      smtp.Timeout = 20000; 
     }