Time out Error in send mail

一个人想着一个人 提交于 2019-12-24 03:06:06

问题


I use this code to try and send an email. After a few seconds, it shows me an error message claiming the operation has timed out. How can I resolve this issue?

try
{
    MailAddress from = new MailAddress("from@yahoo.com", "name", Encoding.UTF8);
    MailAddress to = new MailAddress("to@yahoo.com");
    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("example@yahoo.com", "Password");
    client.Send(message);
    MessageBox.Show("sending Successfully!!!");
}
catch (SmtpException ex)
{
    MessageBox.Show(ex.ToString());
}

回答1:


Are you sure that you can reach smtp.mail.yahoo.com on port 465? Sounds pretty much like a network related issue. Generally when something times out, it means that it tries to connect to the server for a certain amount of time and them stops and gives you an error.

One easy way to test this is to telnet to smtp.mail.yahoo.com on port 465 and see if it times out. You can use Putty or the built in telnet-client in windows, if you have it installed.




回答2:


As per my understanding, your code won't work because yahoo.com does not provide you access via SMTP. For that you need to upgrade to Yahoo! Mail Plus.

Couldn't find any sort of kb from Yahoo! on this. I got the information from a Yahoo! article on How to read Yahoo! Mail Plus using Outlook Express. The first two lines of the article are very relevant.

Do you want to read and send your Yahoo! email with Outlook Express?
If you are a Yahoo! Mail Plus user you can.

And also, the outgoing SMTP server should be

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



回答3:


i had the same problem you have to set the clietn.port as 25 and you have to specify your login an password in client.Credentials = new NetworkCredential(login,password)

when i did that i can send mail without problem

there is the code

{
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("from@yahoo.fr");
                // Set destinations for the e-mail message.
                MailAddress to = new MailAddress("to@gmail.com");
                // 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("from@yahoo.fr", "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.");
}



回答4:


Use following setting for domain @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;
        }


来源:https://stackoverflow.com/questions/6572032/time-out-error-in-send-mail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!