Click here to Skip to main content
11,920,211 members (49,417 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
this is the error i encounter....please answer

No connection could be made because the target machine actively refused it
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: No connection could be made because the target machine actively refused it

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[SocketException (0x274d): No connection could be made because the target machine actively refused it]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239
   System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +224
[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) +5421675
   System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +202
   System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
   System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +332
   System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +160
   System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +159
   System.Net.Mail.SmtpClient.GetConnection() +35
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1213
[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1531
   System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +367
   System.Web.UI.WebControls.PasswordRecovery.AttemptSendPasswordQuestionView() +522
   System.Web.UI.WebControls.PasswordRecovery.AttemptSendPassword() +69
   System.Web.UI.WebControls.PasswordRecovery.OnBubbleEvent(Object source, EventArgs e) +103
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   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) +1565

Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082 
Posted 14-Feb-10 12:27pm
Edited 6-Sep-12 3:31am
Rate this: bad
Please Sign up or sign in to vote.

Solution 7

You've specified the host in your web.config as your local machine: is the loopback address.

If you don't want to set up an SMTP server on your web server, you'll need the configuration of a public one. A quick google suggests Yahoo uses:


Try putting that in your web.config and let us know how you get on.

Yahoo may also require SSL and I don't see a way to specify that here:[^]

Prnda76 23-Feb-13 15:59pm
There is EnableSsl property on the SmtpClient class. So in other words, to send mail via Gmail you can use:

var client = new SmtpClient
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("yourGmailUsername", "yourGmailPassword"),
Host = ""
var message = new MailMessage
// Setup your MailMessage instance here...
Member 11497495 20-Mar-15 3:17am
// Send Regisration number to user's mail box after submitting the form successfully
SmtpClient smtpc = new SmtpClient("");
smtpc.Port =587;
smtpc.EnableSsl = true;
smtpc.UseDefaultCredentials = false;
string user = ""; //<--Enter your gmail id here
string pass = "swapnashankar19";//<--Enter Your gmail password here
string sub = "Form filling Application:"; //Subject for your website
string msg = "Webcome to Your Registration Number is: " + Label2.Text; //Message body
smtpc.Credentials = new NetworkCredential(user, pass);
MailMessage email = new MailMessage(user, TextBox6.Text, sub, msg);
email.IsBodyHtml = true;

Label1.Text = "Your form has been submitted successfully.Take Preview Now,Your Registration Number is: ";
Label3.Text = null;
Rate this: bad
Please Sign up or sign in to vote.

Solution 9

There is a from attribute on the smtp element:[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It could be a couple of things.
  1. is the loop back address to your machine, do you have a mail server running on your machine?
  2. Do you have a firewall running and if so is Port 25 open to receive connections?
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Are you setting the SmtpClient.Host property?

If this is not the problem, please let us see your code that uses a SmtpClient instance - probably LoginUtil.SendPasswordMail.

Rate this: bad
Please Sign up or sign in to vote.

Solution 12

Follow the steps
1. Select the site or Virtual Directory in IIS
2. In Feature View, Right side you see SMTP mail
3. if exists, Click to open a dialogbox
4. Goto Radio button "Store e-mail in pickup directory" enter a valid directory path,
5. Your SMTP starts working, it will not send mails, but all outgoing mail formats you can see, this would be great while debugging, insteading of choking your mail server.

Hope it helps,
dineshvishe 3-Jun-13 1:37am
I am doing For MSSQL Sending mail.Getting error .Any Solution.
Rate this: bad
Please Sign up or sign in to vote.

Solution 14

I think, you need to check your proxy settings in "internet options". If you are using proxy/'hide ip' applications, this problem may be occurs.
Rate this: bad
Please Sign up or sign in to vote.

Solution 15


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

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
3 F-ES Sitecore 130
4 RyanDev 120
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 20 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100