2011-07-04 14 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

ポート465smtp.mail.yahoo.comにアクセスできることは確実ですか?ネットワーク関連の問題とよく似ています。一般的に何かタイムアウトすると、サーバーに一定時間接続しようとしたときに停止し、エラーが表示されます。

これをテストする簡単な方法の1つは、ポート465telnetsmtp.mail.yahoo.comにあり、タイムアウトするかどうかを確認することです。 Puttyまたは組み込まれたtelnet -clientをWindowsにインストールすることができます。

0

yahoo.comはSMTP経由でのアクセスを提供していないため、私の理解によれば、コードは機能しません。そのためにはYahoo!にアップグレードする必要がありますメールプラス

Yahoo!からkbの種類が見つかりませんでしたこれに。私はYahoo!から情報を得たHow to read Yahoo! Mail Plus using Outlook Expressに関する記事。記事の最初の2行は非常に関連性があります。

ヤフーを読んで送信しますか? Outlook Expressのメール?
あなたがYahoo!あなたができるメールプラスユーザー。

そしてまた、送信SMTPサーバーは

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

する必要があります私はあなたが25としてclietn.portを設定する必要があり、あなたのログインクライアントでパスワードを指定する必要が 同じ問題を抱えていました。資格情報=新しいNetworkCredentialの(ログイン、パスワード)

私は問題なくメールを送信できることをやったコード

にあり

ドメイン@yahoo.co.inの設定次

{ 
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

使用。

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; 
     }