0

我通过这篇文章将我的 Outlook 2010 配置 为从 yahoo.com 发送和接收电子邮件,它运行良好,没有任何问题。

我开发了一个小应用程序来通过我的应用程序发送我的电子邮件,但它给了我错误:

"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("myid@yahoo.com", "blabla");
            mailMessage.To.Add(new System.Net.Mail.MailAddress("xxx@live.com", "xxx@live.com"));
            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;
        }
4

1 回答 1

0

来自 MSDN

某些 SMTP 服务器要求在服务器代表客户端发送电子邮件之前对客户端进行身份验证。如果服务器请求此 SmtpClient 对象应使用当前登录用户的默认凭据进行身份验证,则将此属性设置为 true。对于客户端应用程序,这是大多数情况下所需的行为。

UseDefaultCredentials = trueSMTP 服务器发送当前登录用户(即 Windows 用户)的凭据,而不是您定义的凭据。尝试UseDefaultCredentials = false

于 2013-02-14T21:57:57.583 回答