ChangePassword::OnSendMailError Method (SendMailErrorEventArgs^)
Raises the SendMailError event when an e-mail message cannot be sent to the user.
Assembly: System.Web (in System.Web.dll)
Parameters
- e
-
Type:
System.Web.UI.WebControls::SendMailErrorEventArgs^
A SendMailErrorEventArgs object containing the event data.
The OnSendMailError method is called when the SMTP mail system raises an exception while attempting to send an e-mail message after a user has changed a password.
Examine the Exception property of the SendMailErrorEventArgs object passed as the e parameter to determine the actual cause of the exception. The most common reason is a configuration error in the smtp section of the Web.config file.
You must set the Handled property of the object passed as the e parameter to true to signal that the exception has been taken care of; otherwise, the exception is thrown again.
Raising an event invokes the event handler through a delegate. For more information, see Server Event Handling in ASP.NET Web Forms Pages.
The OnSendMailError method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Notes to Inheritors:
When overriding the OnSendMailError method in a derived class, be sure to call the OnSendMailError method for the base class so that registered delegates receive the event.
The following code example demonstrates an ASP.NET page that uses a ChangePassword Web control, and includes an event handler for the SendingMail event named SendingMail. The code example assumes that the ASP.NET Web site has been configured to use ASP.NET membership and Forms authentication, and that a user has been created whose name and password are known to you. For more information, see How to: Implement Simple Forms Authentication.
If the password change succeeds, the code attempts to use SMTP to send an e-mail message to the user to confirm the change. This is done in theSendingMail event handler. For information about how to configure an SMTP server, see NIB: How to: Install and Configure SMTP Virtual Servers in IIS 6.0. For the purposes of this example, it is not necessary to configure an SMTP server; the example is constructed to test for a failure to send an e-mail message.
If a mail server is not configured correctly or some other error occurs and the e-mail message cannot be sent, the SendMailError function is called. A message is displayed to the user. In addition, an event is logged to the Windows Application event log with the assumption that an event source named MySamplesSite already exists. See the code example below to create the specified event source. For more information about creating an event source, see Server Event Handling in ASP.NET Web Forms Pages. The Handled property of the SendMailErrorEventArgs object is set to true to indicate that the error has been handled.
Use the following code example if you need to programmatically add the event source named MySamplesSite to your Application log. This event source must exist in order for the first code example to work correctly. The following code example requires Administrator privileges.
The following example code can be used as the ChangePasswordMail.htm file for the previous example code.
Security Note
|
|---|
Sending user account names or passwords in e-mail is a potential security threat. E-mail messages are typically sent in plain text and can be read by special network "sniffing" applications. To improve security, use the mitigations that are described in Securing Login Controls. |
<html>
<head><title></title></head>
<body>
<form>
<h1>Your password for the account named "<%Username%>" has changed.</h1>
<p>
If you did not initiate this change, please call 1-206-555-0100.
</p>
<p>
<a href="http://www.contoso.com/login.aspx">
<img src="cid:LoginGif" alt="Log In" />
</a>
</p>
<p>
Please read our attached Privacy Notice.
</p>
</form>
</body>
</html>
Available since 2.0
OnBubbleEvent
ChangePassword Class
System.Web.UI.WebControls Namespace
Server Event Handling in ASP.NET Web Forms Pages
ASP.NET Login Controls Overview
Customizing the Appearance of ASP.NET Login Controls
ASP.NET Web Server Controls Templates
How to: Display Different Information to Anonymous and Logged In Users
Web Site Administration Tool Security Tab
Securing Login Controls
Basic Security Practices for Web Applications
Securing Membership
