Hi

I am trying to create a forgot password section within my login section and it doesnt seem to work.

In my forgotpassword.aspx page my code looks like this:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:PasswordRecovery ID="PasswordRecovery1" runat="server" Height="224px" 
        Width="295px"
        SubmitButtonText="Get Password" SubmitButtonType="Link">
  <MailDefinition From="soccervillage@yahoo.com" 
    Subject="Your new password"
    BodyFileName="PasswordRecovery.txt" />
    </asp:PasswordRecovery>
    
</asp:Content>

In my webconfig page the code looks like this:

<system.net>
  <mailSettings>
   <smtp from="soccervillage@yahoo.com">
    <network host="localhost" password="password" userName="username" />
   </smtp>
  </mailSettings>
 </system.net>

I then have created a text file which is called PasswordRecovery.txt and looks like this:

Your password has been reset, <%UserName%>!

According to our records, you have requested that your password be reset. Your new
password is: <%Password%>

If you have any questions or trouble logging on please contact a site administrator.

Thank you!

The error which I am receiving is:

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

Could anyone help me in this situation?


Thanks

Dani AI

Generated

Quick summary: the stack trace shows the app cannot open a TCP connection to the SMTP endpoint (connection refused) or cannot resolve the host. Common causes are using a placeholder hostname (for example literally mail server), DNS problems, no SMTP service listening on that host/port, or outbound SMTP being blocked by the network (very common on campus/ISP networks). was correct to suggest trying an alternate SMTP port and checking the real host; was right that you can’t rely on “localhost” unless an SMTP service is actually running there.

Practical troubleshooting (do these in order):

  • Replace any placeholder host with the real SMTP server name provided by your mail provider or university relay.
  • From the machine running the site, test name resolution and connectivity: nslookup smtp.example.com, then telnet smtp.example.com 25 (or 587). On modern Windows you can use PowerShell: Test-NetConnection -ComputerName smtp.example.com -Port 587. If DNS fails, correct the hostname; if the TCP connect fails, the port is blocked or the server isn’t listening.
  • Check credentials and encryption: many providers require authenticated SMTP with TLS/SSL. Ensure you use the account/password that the SMTP server expects and enable SSL if required.
  • If you’re developing locally or your university blocks outbound SMTP, use a local SMTP test tool (smtp4dev, Papercut) or configure your host to drop messages to a pickup folder rather than sending them out.

Quick code example (use placeholders; adjust to your provider):

using(var smtp = new System.Net.Mail.SmtpClient("smtp.example.com", 587)) {
  smtp.EnableSsl = true;
  smtp.Credentials = new System.Net.NetworkCredential("user@example.com","password");
  smtp.Send("from@example.com","to@example.com","subject","body");
}

Security note (important): do not email plaintext passwords. If you use the ASP.NET PasswordRecovery control, check your membership provider’s passwordFormat. If passwords are hashed they cannot be retrieved — implement a secure reset flow instead: generate a single-use, short-lived token, send a HTTPS link to the user, and let them set a new password. This fixes the immediate SMTP problem and avoids serious security issues.

Recommended Answers

All 21 Replies

Could you please provide StackTrace of the exception?

[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) +5482743
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.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.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) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Since your mailbox is hosted on Yahoo! you need to use their host address, instead of localhost. Here you will get the SMTP settings of all popular email service providers.

For Yahoo, the host is:

However the email I have just made up, does the email have to exist?

Actually I do not have a yahoo email, I have a hotmail. If I am not allowed to make up the email, what should I use for hotmail host?

Yes, the email address should exist. By putting a dummy email address, what you are trying to authenticate?

* Put the proper from address.
* Put appropriate host.
* Supply proper password.

Note: Don't forgot to put the proper To address.

Refer http://www.emailaddressmanager.com/tips/mail-settings.html for SMTP details.

put the proper from address is that the username? And what is the username, the email?


My email is . Could you please state the host name for me?

web.Configu cant send email from localhost

<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="email Address">
<network host="mail server" userName="" password="" <em><strong>port="25"</strong></em> />
</smtp>
</mailSettings>
</system.net>


page.aspx

<asp:PasswordRecovery 
ID="PasswordRecovery1" 
runat="server" 
CssClass="txt" 
ForeColor="Yellow"
GeneralFailureText="" 
QuestionFailureText="" 
SuccessText="" 
UserNameFailureText="">
<MailDefinition 
BodyFileName="<strong><em>PassRecovery.txt</em></strong>" 
From="info@saynacandles.com" 
Priority="High" 
Subject="" 
IsBodyHtml="True">
</MailDefinition>
</asp:PasswordRecovery>


PassRecovery.txt :
<%UserName%>
<%Password%>

In the below code replace YourPassword with your actual password.

<system.net>
	<mailSettings>
		<smtp from="faisal_business@hotmail.co.uk">
			<network host="smtp.live.com" port="25" userName="faisal_business@hotmail.co.uk" password="YourPassword" defaultCredentials="true"/>
		</smtp>
	</mailSettings>
</system.net>

Note: If port 25 has been blocked in your network or by your ISP, you can set SMTP port to 587 with TLS or SSL Encryption depending on the client in use

After making changes too both your replies I still have error. Below is the error which is occuring:

No connection could be made because the target machine actively refused it

Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it

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) +5482743
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

I hope to hear from you soon.

Thank you!

again I say :

U can not Send Mail from Local Host Or MACHINE,

If you look at your smtp settings on the screen shot, it shows the server name, from. And the authentication states the username and password whereas your code which you have provided me with shows something else. Below is the code you provided me with. Could you explain?

<>
<mailSettings>
<smtp deliveryMethod="Network" from="email Address">
<network host="mail server" userName="" password="" port="25" />
</smtp>
</mailSettings>
</>

Did you tried using the port 587?

If you look at your smtp settings on the screen shot, it shows the server name, from. And the authentication states the username and password whereas your code which you have provided me with shows something else. Below is the code you provided me with. Could you explain?

<>
<mailSettings>
<smtp deliveryMethod="Network" from="email Address">
<network host="mail server" userName="" password="" port="25" />
</smtp>
</mailSettings>
</>

ok

network host is same as server name, usually it's your domain name.
user name and password is for access your mail.
from, is your email address that you sending mail from it.

now i have a question,
are you try to sending mail from local machine?

No I try sending it from University computers

Knvn - No i did not try using that port, should I try that?

your university's computers is mail server?
i think u must try it from a real domain over the internet

If I use mail server the error i receive is:

The remote name could not be resolved: 'mail server'

Exception Details: System.Net.WebException: The remote name could not be resolved: 'mail server'

Stack Trace:


[WebException: The remote name could not be resolved: 'mail server']
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +5482743
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

That means the computer asked for the IP-address of smtp.yourdomain.xxx at your configurated DNS server and this returned it couldn't find an IP-address for smtp.yourdomain.xxx

So question is: is smtp.yourdomain.xxx a valid address?

Is there a DNS server configured at the computer and has this DNS server a valid DNS entry for smtp.yourdomain.xxx

Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it

Stack Trace:

[SocketException (0x274d): No connection could be made because the target machine actively refused it ]

Some ISP's do block the port 25. This might be the cause for above exception. Just try with the port 587.

Also, try by specifying the below hosts:

I did not understand that link, I will speak to a tutor maybe find the right host name. Thanks for help anyway!!

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.