locked
SmtpClient.Send() problem results in "An established connection was aborted by the software in your host machine" RRS feed

  • Question

  • Hi,

    I'm having problems with SmtpClient.Send() where I end with an "An established connection was aborted by the software in your host machine" type error. My infrastructure people tell me that I should have access to the Smtp server so things should just work. I've been
    googling and searching forums but have yet to see a complete answer to what this error is trying to tell me. Oh and I've tried this in both a Web and a WinForm app on .Net framework 2.0 running on a clean install of XP Pro.

    Any opinions ?

    Thanks Scott.

    This is the code (massaged for security):

    protected void SendEmail()
    {
        MailAddress addressFrom = new MailAddress("sender@domain.com");
        MailAddress addressTo   = new MailAddress("recipient@domain.com");
        MailMessage msg         = new MailMessage(addressFrom, addressTo);
        try
        {
            string host = "servername.domain.com";

            msg.Subject = "Test Subject";
            msg.Body    = "Test Body";

            SmtpClient email    = new SmtpClient();
            email.Host            = host;
            email.Port            = 25;
            email.EnableSsl    = false;
            email.DeliveryMethod = SmtpDeliveryMethod.Network;

            NetworkCredential credentials = new NetworkCredential("username", "password", "domain");
            email.Credentials = credentials;
    //      email.Credentials = CredentialCache.DefaultNetworkCredentials;
            email.Send(msg);
        }
        catch (Exception e)
        {
            ProcessUnhandledException(e);
        }
        finally
        {
            msg.Dispose();
        }
    }

    I've traced the problem and the resultant log is as follows :

    System.Net Verbose: 0 : [3492] SmtpClient::.ctor()
    System.Net Information: 0 : [3492] Associating SmtpClient#58000584 with SmtpTransport#52243212
    System.Net Verbose: 0 : [3492] Exiting SmtpClient::.ctor()     -> SmtpClient#58000584
    System.Net Verbose: 0 : [3492] SmtpClient#58000584::Send(MailMessage#426867)
    System.Net Information: 0 : [3492] SmtpClient#58000584::Send(DeliveryMethod=Network)
    System.Net Information: 0 : [3492] Associating SmtpClient#58000584 with MailMessage#426867
    System.Net Information: 0 : [3492] Associating SmtpTransport#52243212 with SmtpConnection#3841804
    System.Net Information: 0 : [3492] Associating SmtpConnection#3841804 with ServicePoint#34576242
    System.Net.Sockets Verbose: 0 : [3492] Socket#42750725::Socket(InterNetwork#2)
    System.Net.Sockets Verbose: 0 : [3492] Exiting Socket#42750725::Socket()
    System.Net.Sockets Verbose: 0 : [3492] Socket#42750725::Connect(35:25#590282771)
    System.Net.Sockets Error: 0 : [3492] Exception in the Socket#42750725::Connect - An established connection was aborted by the software in your host machine
    System.Net.Sockets Verbose: 0 : [3492] Socket#42750725::Connect(35:25#598671379)
    System.Net.Sockets Error: 0 : [3492] Exception in the Socket#42750725::Connect - An established connection was aborted by the software in your host machine
    System.Net.Sockets Verbose: 0 : [3492] Socket#42750725::Close()
    System.Net.Sockets Verbose: 0 : [3492] Socket#42750725::Dispose()
    System.Net.Sockets Verbose: 0 : [3492] Exiting Socket#42750725::Close()
    System.Net.Sockets Verbose: 0 : [3492] Socket#42750725::Dispose()
    System.Net.Sockets Verbose: 0 : [3492] Exiting Socket#42750725::Dispose()
    System.Net Error: 0 : [3492] Exception in the SmtpClient#58000584::Send - Unable to connect to the remote server
    System.Net Error: 0 : [3492]    at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
       at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
       at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
       at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
       at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
    System.Net Verbose: 0 : [3492] Exiting SmtpClient#58000584::Send()
    System.Net Information: 0 : [3492] Associating MailMessage#26765710 with Message#39564799
    System.Net Verbose: 0 : [3492] SmtpClient::.ctor(host=
    servername.domain.com, port=25)
    System.Net Information: 0 : [3492] Associating SmtpClient#20538874 with SmtpTransport#50632145
    System.Net Verbose: 0 : [3492] Exiting SmtpClient::.ctor()     -> SmtpClient#20538874
    System.Net Verbose: 0 : [3492] SmtpClient#20538874::Send(MailMessage#26765710)
    System.Net Information: 0 : [3492] SmtpClient#20538874::Send(DeliveryMethod=Network)
    System.Net Information: 0 : [3492] Associating SmtpClient#20538874 with MailMessage#26765710
    System.Net Information: 0 : [3492] Associating SmtpTransport#50632145 with SmtpConnection#53036123
    System.Net Information: 0 : [3492] Associating SmtpConnection#53036123 with ServicePoint#7563067
    System.Net.Sockets Verbose: 0 : [3492] Socket#958745::Socket(InterNetwork#2)
    System.Net.Sockets Verbose: 0 : [3492] Exiting Socket#958745::Socket()
    System.Net.Sockets Verbose: 0 : [3492] Socket#958745::Connect(35:25#590282771)
    System.Net.Sockets Error: 0 : [3492] Exception in the Socket#958745::Connect - An established connection was aborted by the software in your host machine
    System.Net.Sockets Verbose: 0 : [3492] Socket#958745::Connect(35:25#598671379)
    System.Net.Sockets Error: 0 : [3492] Exception in the Socket#958745::Connect - An established connection was aborted by the software in your host machine
    System.Net.Sockets Verbose: 0 : [3492] Socket#958745::Close()
    System.Net.Sockets Verbose: 0 : [3492] Socket#958745::Dispose()
    System.Net.Sockets Verbose: 0 : [3492] Exiting Socket#958745::Close()
    System.Net.Sockets Verbose: 0 : [3492] Socket#958745::Dispose()
    System.Net.Sockets Verbose: 0 : [3492] Exiting Socket#958745::Dispose()
    System.Net Error: 0 : [3492] Exception in the SmtpClient#20538874::Send - Unable to connect to the remote server
    System.Net Error: 0 : [3492]    at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
       at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
       at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
       at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
       at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
    System.Net Verbose: 0 : [3492] Exiting SmtpClient#20538874::Send()

    Friday, March 3, 2006 12:06 AM

Answers

  • The problem is our virus scanner doing the blocking.

    We run McAfee version 8 and so our infrastructure people are looking at the problem now to create a rule to allow Smtp traffic out of developer boxes.


    Cheers
    Scott
    Friday, March 3, 2006 2:42 AM
  • Sorry to resurrect this thread, but I am having the exact same problem. ASP.Net 2.0 and McAfee 8.0.

    I have added w3wp.exe to the exceptions but it still doesn't work, the log shows:

    10/1/2007    9:35:27 AM    Blocked by port blocking rule     w3wp.exe    Prevent mass mailing worms from sending mail    127.0.0.1
    10/1/2007    9:38:27 AM    Blocked by port blocking rule     w3wp.exe    ?    127.0.0.1

    The first corresponds to the rule I added the exception to, but does anyone know what the second with the question mark refers to?

    Thanks for any help...

    • Proposed as answer by Kokken1 Tuesday, August 19, 2008 7:09 AM
    • Marked as answer by CaddreModerator Tuesday, August 19, 2008 2:59 PM
    Monday, October 1, 2007 8:49 AM

All replies

  • The problem is our virus scanner doing the blocking.

    We run McAfee version 8 and so our infrastructure people are looking at the problem now to create a rule to allow Smtp traffic out of developer boxes.


    Cheers
    Scott
    Friday, March 3, 2006 2:42 AM
  • Ah Ha!

    This too is our problem. Thanks!

    Have you come up with a solution yet? We are working on one too.

    We have several in house programs that send diagnostic and debug information to an automated bug tracking system via smtp, so this is definately going to be an issue.

    Thursday, March 16, 2006 12:06 PM
  • Hi People,

    I ran into the same problem. The solution to it is Open McAfee Virusscan console. Double click Access Protection, Select the first rule corresponding to port 25 (default smtp port). Double click on it, in the excluded processes list you would see that inetinfo.exe is present. This was for iis5.0 and iis5.1, the asp.net 2.0 worker process runs as w3wp.exe. Thus add w3wp.exe to the process list and you should be able to get it running.

     

    kunal

    Wednesday, March 29, 2006 8:19 PM
  • All,

    If you're running VS.NET 2005 and your web application is using the ASP.NET Development Server (instead of IIS), the process name to add to the excluded processes list is: WebDev.WebServer.exe.

    S.

    Wednesday, April 12, 2006 11:20 PM
  • Dear All

    Thanks for the advice so far, it allowed me to track my similar problem. I checked the McAfee log and found that it was my aspnet_wp.exe process that was being blocked (VS2005). I added that to the list and all works

     

    MM

     

    Saturday, April 15, 2006 3:29 PM
  • I found the same problem.

    Should I change the config of my computer , or the mail server?

    The anti-virus software here is Norton.

     

    Wednesday, May 17, 2006 1:42 AM
  •  

     

    we are working on console application in asp.net 2.0.For this which process we have to put on excluded process list.

    Your Solution is applicable only for web applications.

     

    kg81

    Tuesday, May 23, 2006 6:34 AM
  • Thanks, it works fine with:

    • Visual Studio 2005
    • McAfee VirusScan Enterprise 8

     

     

    Monday, August 28, 2006 8:52 AM
  • yes, if using VS.NET 2005 add WebDev.WebServer.exe into the list. Thank you!
    Monday, August 28, 2006 2:55 PM
  • Hi,

    I have the same problem. Your comment is very helpful. I followed your idea and added my process name to the "excluded processes", then it works. Thanks.

    Thursday, October 26, 2006 6:40 PM
  • good idea, my case the problem was the firewall 
    Wednesday, January 17, 2007 3:42 AM
  • This is bcoz of the  antivirus which is blocked by the windows firewall,

     just add the antivirus to the windows firewall ,in windows firewall  Exception tab -->AddProgram and select the antivirus which is installed in your system .. this will solve the prob for ASP.net application ..

    Friday, March 30, 2007 5:29 AM
  • Make sure your ApplicationName.exe is not been block by the firewall.
    Sunday, April 15, 2007 11:25 PM
  •  

    If  you are using DataBaseMail in SQL Server 2005, the file is databasemail90.exe.

     

    Cheers,

    Mahesh. 

    Wednesday, April 25, 2007 8:26 AM
  • Your suggestion was absolutely on the mark.   I'm using SMTP from a console app.  Just added the name of my app. to the exception list.

     

    I wish I would have looked here sooner.

     

    Thanks!

    Tuesday, July 17, 2007 1:48 PM
  • Sorry to resurrect this thread, but I am having the exact same problem. ASP.Net 2.0 and McAfee 8.0.

    I have added w3wp.exe to the exceptions but it still doesn't work, the log shows:

    10/1/2007    9:35:27 AM    Blocked by port blocking rule     w3wp.exe    Prevent mass mailing worms from sending mail    127.0.0.1
    10/1/2007    9:38:27 AM    Blocked by port blocking rule     w3wp.exe    ?    127.0.0.1

    The first corresponds to the rule I added the exception to, but does anyone know what the second with the question mark refers to?

    Thanks for any help...

    • Proposed as answer by Kokken1 Tuesday, August 19, 2008 7:09 AM
    • Marked as answer by CaddreModerator Tuesday, August 19, 2008 2:59 PM
    Monday, October 1, 2007 8:49 AM
  • Kunal,

     

    I added my app to the exception list and it worked immediately.

    Thanks for taking the time to post the McAfee VirusScan port 25 solution!. You saved me hours of grief !

     

    thanks - mark

    Tuesday, April 15, 2008 5:18 PM
  • I've had several problems with this mail blocking feature.
    None of my scripts or applications was able to sent a mail with our business intelligence information.
    If the Mail Blocking was disabled in MCAfee Enterprise then it would be enabled the again the next morning - so no information could be mailed out that night!
    I also tried to enter the exe-names of my applications in the list in the MCAfee program. But also this list would be reset the next day.
    So to get it all function, i had to give my program a name like one of the far well known mailprograms (like Eudora, Pegasus).
    I finally renamed my application to eudora.exe - and now the mail blocker in MCAfee was satisfied! - Yes so simple it is to go beyond this mail blocker feature, which has cost so much trouble to me and probably several others.
    Tuesday, August 19, 2008 7:27 AM
  •   I used this sample code to send mail  notification using net.mail but i get the error which is shown in stack trace.
    I also added the process w3wp.exe since i have macfee . But its still the same


    dr = dt.Rows[0];

    string pwd = dr["nvpassword"].ToString();

     

    MailMessage email = new MailMessage();
    email.From = new MailAddress("xyz@gmail.com");

    email.To.Add(

    new MailAddress(tomail));
    email.Subject = "Forgot Password";

    email.Body =

    "Hello your password is " + "," + pwd;
    SmtpClient client = new SmtpClient("localhostname");

    client.Send(email);

    // ...........//3rd try but it gives error at this client.Send .

    cm.MsgBox(

    "Password has been sent to your email. Please check your mail and login back", this);

     

    in web .config 

    <

    system.net>
    <mailSettings>

    <

    smtp deliveryMethod="Network">
    <network host="localhost" port="25" defaultCredentials="true" />

    </

    smtp>
    </mailSettings>

    </

    system.net>

     

     

     

    But it gives error at client.Send(email);

    saying

     

     


    Monday, September 8, 2008 6:02 PM
  • If you have smtp setup in IIS, just change your delivery method from network to use iis:

    SmtpClient mail = new SmtpClient(MailSettings.Settings.Host);

    mail.DeliveryMethod =
    SmtpDeliveryMethod.PickupDirectoryFromIis;

    mail.Send(msg);

    • Proposed as answer by XioPod Monday, March 23, 2009 12:28 PM
    Monday, March 23, 2009 12:27 PM
  • Hi kunal,

    I must thank you for suggesting this solution for this problem.
    I got solved my problem by this. Now i am able to run my mail properly.


    Sudhakar
    Wednesday, September 9, 2009 5:39 AM