Link to home
Start Free TrialLog in
Avatar of TimAttaway
TimAttawayFlag for United States of America

asked on

Sending Email - Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

I recently upgraded my computer at work and since then I cannot send email from applications running on my local computer.  This worked before the upgrade.  There is obviously some setting that needs to be tweaked but I don't know what it is.  Below is a very simple example of something that fails.  When it gets to the "theClient.Send(theEmailToSend)" it gets an exception and the message is: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

When i run this same code on a server as part of a Web application (with "theClient.Host" set to a proper IP address) it works fine.  I've always been able to change the host to "localhost" for my testing, but now it does not work.

Any ideas?

Thanks in advance.



System.Net.Mail.MailMessage theEmailToSend = new System.Net.Mail.MailMessage();
            System.Net.Mail.MailAddress theRecipient = new System.Net.Mail.MailAddress("TimAttaway@mchapusa.com", "Tim Attaway");
            theEmailToSend.To.Add(theRecipient);
            System.Net.Mail.MailAddress FromAddress = new System.Net.Mail.MailAddress("TimAttaway@mchapusa.com", "Tim Attaway");
            theEmailToSend.From = FromAddress;
            theEmailToSend.Body = "This is a simple email.";
            theEmailToSend.IsBodyHtml = false;
            theEmailToSend.Subject = "Email Test";
            System.Net.Mail.SmtpClient theClient = new System.Net.Mail.SmtpClient();
            theClient.Host = "localhost";
            theClient.Port = 25;
            theClient.Send(theEmailToSend);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nycynik
nycynik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TimAttaway

ASKER

Actually the first problem was that SMTP service had never been installed on my local system.  I went to Control Panel -> Add/Remove Programs -> Add/Remove Windows Components -> IIS -> Details and clicked on SMTP Service to get that installed.  The next step was to get th email server to accept mail from my computer.  Thanks.
Provided me a direction but did not supply the whole solution.