Click here to Skip to main content
14,982,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
[SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:25]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +208
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +464

[WebException: Unable to connect to the remote server]
   System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) +6646520
   System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +307
   System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +19
   System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +324
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +141
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
   System.Net.Mail.SmtpClient.GetConnection() +44
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1554

[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
   ContactUs.SendDetails() in d:\ClickPerks\ClickPerks\httpdocs\ContactUs.aspx.cs:48
   ContactUs.btnSubmit_Click(Object sender, EventArgs e) in d:\ClickPerks\ClickPerks\httpdocs\ContactUs.aspx.cs:54
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628114
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   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) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724


private void SendDetails()
    {
        System.Text.StringBuilder oBuilder = new System.Text.StringBuilder();
        oBuilder.Append("Email=" + txtEmail.Text + Environment.NewLine);
        oBuilder.Append("Name=" + txtName.Text + Environment.NewLine);
        oBuilder.Append("Subject=" + txtSubject.Text + Environment.NewLine);
        oBuilder.Append("Message=" + txtDetails.Text);

        MailMessage oMM = new MailMessage();
        oMM.From = new MailAddress("info@clickperks.com");
        try
        {
            oMM.ReplyTo = new MailAddress("info@clickperks.com");
        }
        catch
        {
        }
        oMM.Subject = txtSubject.Text;
        oMM.Body = oBuilder.ToString();
        oMM.To.Add(ConfigurationManager.AppSettings.Get("ContactUsReceiverEmailID").ToString());
        SmtpClient client = new SmtpClient();
        client.Host = ConfigurationManager.AppSettings.Get("SMTPServerName").ToString();
        client.Send(oMM);
    }
    public void btnSubmit_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            SendDetails();
            lblConfirmation.Text = "<br>Your details have been successfully submitted.  You should receive a response from us within two business days.<br>";
            txtEmail.Text = "";
            txtName.Text = "";
            txtSubject.Text = "";
            txtDetails.Text = "";

        }
    }


What I have tried:

Here actually I tried removing windows firewall, proxy, restarted VS but didn't work.I don't have any knowledge on webservice, if this error is related to that. Please help me out in this. I'm receiving error in
client.Send(oMM);
line
Posted
Updated 9-Jan-17 3:17am
Comments
Michael_Davies 9-Jan-17 2:45am
   
Do you have an SMTP service running on your PC?
Amith 12807185 9-Jan-17 3:10am
   
Hi Michael,
I tried telnet smtp.mydomain.com 25
connection failed. I think it is not getting connected.
F-ES Sitecore 9-Jan-17 4:15am
   
Your code is trying to send email using the local machine as the SMTP server. Unless you have an SMTP service running on it it's not going to work. If this is just for development try something like smtp4dev which is a GUI app that acts as a local SMTP service and lets you see the content of the emails (it doesn't actually send anything though). If this isn't for local development then you need to configure your code to use a working SMTP server.
Amith 12807185 9-Jan-17 7:45am
   
ok F-ES Sitecore, I'll try with the smtp4dev and share my findings.
Amith 12807185 10-Jan-17 5:23am
   
F-ES Sitecore, thanks for the insight, it worked. Thing is it's not development so I need to configure my code as you suggested.

1 solution

Here is an example to send email using other email provider such as the Gmail

ASP.NET Send email using GMAIL[^]

You can update the client.Port and client.Host to fit in other email provider.
   
Comments
Amith 12807185 10-Jan-17 2:54am
   
Thank You so much Bryian, it worked!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900