0

i config my outlook 2010 by thie article to send and receive email from yahoo.com it works good without any problem.

i develop a small application to send my emails by my application but it gave me errors:

"unable to read data from the transport connection:an exist connection was 
 forcibly closed by the remote host."

my codes:

  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;
        }
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108
  • I don't think you should be using the `UseDefaultCredentials` property along with `Credentials`. I would set `UseDefaultCredentials` to false. That property will cause the SmtpClient to try and use the current users system credentials – Adam Plocher Feb 14 '13 at 21:56
  • @Adam i tested it by smtp.UseDefaultCredentials = false;, not works has the same error but thanks for your help – motevalizadeh Feb 14 '13 at 21:58
  • take a look at this: http://stackoverflow.com/questions/5092235/c-sharp-smtp-email-sending-code-fails-for-yahoo-mail-but-works-fine-for-other-se – Adam Plocher Feb 14 '13 at 22:02

1 Answers1

0

From MSDN

Some SMTP servers require that the client be authenticated before the server sends e-mail on its behalf. Set this property to true when this SmtpClient object should, if requested by the server, authenticate using the default credentials of the currently logged on user. For client applications, this is the desired behavior in most scenarios.

The UseDefaultCredentials = true sends to the SMTP server the credentials of the current logged in user (i.e. the Windows User) not the credentials you have defined. Try with UseDefaultCredentials = false

Steve
  • 213,761
  • 22
  • 232
  • 286