This documentation is archived and is not being maintained.

SendMailErrorEventHandler Delegate

Represents the method that handles the SendMailError event of controls such as the ChangePassword control, the CreateUserWizard control, and the PasswordRecovery control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public delegate void SendMailErrorEventHandler (
	Object^ sender, 
	SendMailErrorEventArgs^ e
)
/** @delegate */
public delegate void SendMailErrorEventHandler (
	Object sender, 
	SendMailErrorEventArgs e
)
Not applicable.

Parameters

sender

The source of the event.

e

A SendMailErrorEventArgs object that contains the event data.

When you create a SendMailErrorEventHandler delegate, you identify the method that will handle the event. To associate the event with the event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate from the event. For more information about event-handler delegates, see Server Event Handling in ASP.NET Web Pages.

Handling the SendMailError event allows your Web application to continue running, even if an exception occurs when trying to send an e-mail message. For example, this is useful if the exception occurs when a user is working through a multi-step wizard. It is preferable to log the error, display an informative message to the user, and allow the user to complete the wizard rather than terminate the application.

If you do not create an event handler for the SendMailError event, or if you create an event handler but leave the Handled property set to false, your Web application will stop running if an error occurs when sending an e-mail message, and ASP.NET will display an error message.

The OnSendMailError method also allows derived classes to handle the event instead of the SendMailErrorEventHandler. This is the preferred technique for handling the event in a class that is derived from ChangePassword or CreateUserWizard.

For more information about handling events, see Server Event Handling in ASP.NET Web Pages.

The following code example demonstrates an ASP.NET page that uses a ChangePassword Web control, and includes an event handler for the SendMailError event named SendMailError. 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 the SendingMail event handler. For information about how to configure an SMTP server, see How to: Configure an SMTP Virtual Server. 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 Pages. The Handled property of the SendMailErrorEventArgs object is set to true to indicate that the error has been handled.

No code example is currently available or this language may not be supported.

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.

No code example is currently available or this language may not be supported.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: