我配置我的Outlook 2010的thie article發送和接收來自yahoo.com的電子郵件,它工作正常,沒有任何問題。雅虎smtp發送電子郵件時發生錯誤
我開發一個小應用程序通過我的應用程序發送我的電子郵件,但它給我的錯誤:
"unable to read data from the transport connection:an exist connection was
forcibly closed by the remote host."
我的代碼:
try
{
SmtpClient smtp = new SmtpClient("smtp.mail.yahoo.com", 465);
smtp.UseDefaultCredentials = true;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("myid", "mypass");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mailMessage = new MailMessage();
mailMessage.From = new System.Net.Mail.MailAddress("[email protected]", "blabla");
mailMessage.To.Add(new System.Net.Mail.MailAddress("[email protected]", "[email protected]"));
mailMessage.Subject = "test";
mailMessage.Body = "test";
mailMessage.IsBodyHtml = false;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Priority = MailPriority.High;
smtp.Send(mailMessage);
Console.WriteLine("hooooooooooraaaaaaaaaaaaaaa");
Console.ReadKey();
}
catch (Exception err)
{
Console.WriteLine(err.InnerException.Message);
Console.ReadKey();
return;
}
我不認爲你應該使用'UseDefaultCredentials'屬性以及'Credentials'。我會將UseDefaultCredentials設置爲false。該屬性將導致SmtpClient嘗試使用當前用戶的系統憑據 – 2013-02-14 21:56:18
@Adam我通過smtp.UseDefaultCredentials = false測試了它;不工作具有相同的錯誤,但感謝您的幫助 – motevalizadeh 2013-02-14 21:58:53
請看一下:http:/ /stackoverflow.com/questions/5092235/c-sharp-smtp-email-sending-code-fails-for-yahoo-mail-but-works-fine-for-other-se – 2013-02-14 22:02:28