Problem with the contact form page. Displays below Once you click the send button .

A socket operation was attempted to an unreachable host 74.125.193.108:587
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable host 74.125.193.108:587

Source Error:

Line 32: smtp.Credentials = NetworkCred;
Line 33: smtp.Port = 587;
Line 34: smtp.Send(mm);
Line 35: lblMessage.Text = "Email Sent SucessFully.";
Line 36:

Source File: d:\hshome\c311399\onthegoventuresng.org\Contact.aspx.cs Line: 34

Dani AI

Generated

The stack trace shows a failed outbound TCP connection to 74.125.193.108:587 (one of Gmail’s SMTP addresses). That means the web server never completed a TCP/TLS connection to the mail server — most often a network-level block (firewall, host/ISP blocking outbound SMTP) or a remote authentication/TLS policy preventing the session. This expands on ’s credential note and ’s network-suggestion: fixing credentials is necessary but won’t help if the port is blocked.

Quick, ordered checks (run from the webhost/server where Contact.aspx runs):

telnet smtp.gmail.com 587
nslookup smtp.gmail.com
tracert smtp.gmail.com # Windows; use traceroute on Linux
openssl s_client -starttls smtp -connect smtp.gmail.com:587

If telnet/openssl times out or never shows the SMTP banner, the host or provider is blocking outbound SMTP — contact the hosting provider or use their relay. If the TCP/TLS handshake succeeds but SmtpClient still fails at auth, check Gmail account security (2‑Step Verification / App Passwords) and Google’s “less secure apps” changes: modern Gmail connections often require an App Password or OAuth. (stackoverflow.com)

If the server connects but errors continue, capture detailed diagnostics by enabling System.Net tracing in web.config (creates a network log showing socket/TLS activity). Example snippet to add under <configuration> (write a small trace file and inspect it after a failed send):

<system.diagnostics>
<sources>
<source name="System.Net" switchValue="Verbose">
<listeners>
<add name="NetTrace"/>
</listeners>
</source>
<source name="System.Net.Sockets" switchValue="Verbose">
<listeners>
<add name="NetTrace"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="NetTrace" type="System.Diagnostics.TextWriterTraceListener" initializeData="System.Net.trace.log"/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>

This log will show DNS resolution, socket connect attempts and TLS handshakes — useful when the hosting provider claims “no block.” (stackoverflow.com)

Longer-term: if Gmail is required and modern auth is needed, move away from legacy SmtpClient-based approaches to libraries that support OAuth2 (for example MailKit is the recommended modern option). If the provider blocks SMTP, use the host’s SMTP relay or a transactional relay service. (learn.microsoft.com)

Summary checklist for the thread: run the connectivity commands, enable System.Net tracing, verify Google account auth (App Password/OAuth), and if TCP connections fail, escalate to the hosting provider for an outbound-SMTP exception or use the host’s relay.

Recommended Answers

All 11 Replies

Please any help ?

Apparently, your specified host is unreachable or rejecting your connection. What server is that? Your own?

Or, the network where this web server is located on is not allowing connections to a remote host at all or on that port. gmail mail server?

This is what is on my front page. It is still bring the error below

ERROR MESSAGE

Server Error in '/' Application.

A socket operation was attempted to an unreachable host 74.125.193.108:587
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable host 74.125.193.108:587

Source Error:

Line 32: smtp.Credentials = NetworkCred;
Line 33: smtp.Port = 587;
Line 34: smtp.Send(mm);
Line 35: lblMessage.Text = "Email Sent SucessFully.";
Line 36:

Source File: d:\hshome\c311399\onthegoventuresng.org\Contact.aspx.cs Line: 34

Stack Trace:

[SocketException (0x2751): A socket operation was attempted to an unreachable host 74.125.193.108:587]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +251
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +279

[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +6136880
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +314
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +322
System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +146
System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +222
System.Net.Mail.SmtpClient.GetConnection() +50
System.Net.Mail.SmtpClient.Send(MailMessage message) +1496

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1829
Contact.btnSend_Click(Object sender, EventArgs e) in d:\hshome\c311399\onthegoventuresng.org\Contact.aspx.cs:34
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1022

Contact.aspx page

   **Contact.aspx.cs page**

   using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;

public partial class Contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        MailMessage mm = new MailMessage("xxx@gmail.com", "info@onthegoventuresng.org");
        mm.Subject = txtSubject.Text;
        mm.Body = "Name: " + txtName.Text + "<br /><br />Email: " + txtEmail.Text + "<br />" + txtBody.Text;
        if (FileUpload1.HasFile)
        {
            string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
            mm.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));
        }
        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
        NetworkCred.UserName = "xxx@gmail.com";
        NetworkCred.Password = "xxx";
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        lblMessage.Text = "Email Sent SucessFully.";

        txtName.Text = "";
        txtEmail.Text = "";
        txtBody.Text = "";
    }
    private void Exit(int p)
    {
        throw new NotImplementedException();
    }



}







<div class="col-sm-9">

    <h4>For all your Request Please fill Form Below</h4>
      <table border = "0" style="width: 409px">
    <tr>
        <td>
            <asp:Label ID="Label1" runat="server" Text="Name*"></asp:Label><br />
        </td>
        <td>
            <asp:TextBox ID="txtName" runat="server" ValidationGroup = "contact"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
             ControlToValidate = "txtName"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label2" runat="server" Text="Subject*"></asp:Label><br />
        </td>
        <td>
            <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
             ControlToValidate = "txtSubject"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label3" runat="server" Text="Email*"></asp:Label><br />
        </td>
        <td>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />
            <asp:RegularExpressionValidator id="valRegEx" runat="server"
            ControlToValidate="txtEmail"
            ValidationExpression=".*@.*\..*"
            ErrorMessage="*Invalid Email address."
            display="dynamic">
            </asp:RegularExpressionValidator>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*"
            ControlToValidate = "txtEmail"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td valign = "top" >
            <asp:Label ID="Label4" runat="server" Text="Body*"></asp:Label>
        </td>
        <td>
            <asp:TextBox ID="txtBody" runat="server" TextMode = "MultiLine" ></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*"
            ControlToValidate = "txtBody"></asp:RequiredFieldValidator>
        </td>
    </tr>
     <tr>
        <td></td>
        <td>
            <asp:FileUpload ID="FileUpload1" runat="server" />
       </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" />
       </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <asp:Label ID="lblMessage" runat="server" Text="" ForeColor = "Green"></asp:Label>
       </td>
    </tr>
</table>
    </div>

Shouldn't

smtp.UseDefaultCredentials = true;

be:

smtp.UseDefaultCredentials = false;

i corrected that and it still giving the same error

Not sure then, check your firewall.

I tried it on another system it still brings that error

This is my web config file and i am using a visual studio 2012 versio

    <?xml version="1.0"?>



    <configuration>

        <system.web>
          <customErrors mode="Off"></customErrors>

        <compilation debug="true"></compilation>

        </system.web>



      <appSettings>
          <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" ></add>
        </appSettings>

    </configuration>

I tried it on another system it still brings that error

Firewall somewhere else then? Something is blocking the port, at least looks like it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.