1
votes

hi Dear all im getting issue

InnerException = Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

MailMessage mail = new MailMessage("[email protected]", "[email protected]");
        SmtpClient client = new SmtpClient("mail.electronichealthcaresystem.net", 25);
        client.DeliveryMethod = SmtpDeliveryMethod.Network;

    client.UseDefaultCredentials = true;
    client.Credentials = new System.Net.NetworkCredential("[email protected]", "123");
    mail.Subject = "Testing";


    mail.Body = "testing";

    try
    {
        client.Send(mail);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
              ex.ToString());
    }
1
did you try to send an email using telnet? network credentials and parameters are double chekced?Paolo
Your ISP is probably blocking port 25.SLaks

1 Answers

0
votes

Since you set:

client.UseDefaultCredentials = true;

The credentials you are setting in:

client.Credentials = new System.Net.NetworkCredential("[email protected]", "123");

are not being used. The default credentials (credentials of the currently logged in user) are being sent. This could cause the mail server to refuse the connection if the second set of credentials are the correct ones.

To use the second set of credentials set:

client.UseDefaultCredentials = false;