我使用此代码尝试发送电子邮件。几秒钟后,它显示一条错误消息,声称操作已超时。我该如何解决这个问题?
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());
}
答案 0 :(得分:2)
您确定可以通过端口smtp.mail.yahoo.com
访问465
吗?听起来很像网络相关的问题。通常,当某些事情超时时,这意味着它会尝试连接到服务器一段时间,然后停止并给您一个错误。
一种简单的方法是对端口telnet
上的smtp.mail.yahoo.com
到465
进行测试,看看它是否会超时。如果已安装,可以在Windows中使用Putty
或内置telnet
- 客户端。
答案 1 :(得分:0)
根据我的理解,您的代码将无法正常工作,因为yahoo.com不会通过SMTP提供您的访问权限。为此,您需要升级到 Yahoo! Mail Plus 。
无法从Yahoo!中找到任何类型的kb就此而言。我从雅虎获得了信息!关于How to read Yahoo! Mail Plus using Outlook Express的文章。本文的前两行非常相关。
您想阅读并发送您的Yahoo!使用Outlook Express发送电子邮件?
如果你是雅虎!您可以使用Mail Plus用户。
此外,外发SMTP服务器应为
client.Host = "plus.smtp.mail.yahoo.com";
答案 2 :(得分:0)
当我这样做时,我可以毫无问题地发送邮件
有代码
{
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.");
}
答案 3 :(得分: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;
}