Provides data for the SendMailError event of controls such as the System.Web.UI.WebControls.ChangePassword control, the System.Web.UI.WebControls.CreateUserWizard control, and the System.Web.UI.WebControls.PasswordRecovery control.
See Also: SendMailErrorEventArgs Members
The System.Web.UI.WebControls.SendMailErrorEventArgs object contains an error message that is raised by the SMTP mail provider when an e-mail message cannot be sent by the System.Web.UI.WebControls.ChangePassword control, or the System.Web.UI.WebControls.CreateUserWizard control. In such a case, the System.Web.UI.WebControls.SendMailErrorEventArgs object is sent to the System.Web.UI.WebControls.SendMailErrorEventHandler.
Create a System.Web.UI.WebControls.SendMailErrorEventHandler delegate to handle the event. Handling the event allows your Web application to continue to run even though an exception has occurred. This is useful when it is not critical to send an e-mail message. For example, if the exception occurs when a user is working through a multi-step wizard, it can be advantageous to log the error, display an informative message to the user, and allow the user to complete the wizard.
Examine the SendMailErrorEventArgs.Exception property to determine the actual cause of the exception. The most common reason for the exception is a configuration error in the smtp Element (Network Settings) of the machine configuration file. Although an error like this is typically discovered during the development and debugging of an application, mail servers can fail unexpectedly in a production environment, and you must determine whether you want the entire application to fail in that situation. If not, handling the event allows your application to proceed.
You must set the SendMailErrorEventArgs.Handled property to true to signal that the exception has been handled; otherwise, the exception is rethrown, and will include the original call stack and error message.
If you do not create an event handler for the ChangePassword.SendMailError event, or if you create an event handler but leave the SendMailErrorEventArgs.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 ChangePassword.OnSendMailError(SendMailErrorEventArgs) method also allows derived classes to handle the event, instead of this being done by the System.Web.UI.WebControls.SendMailErrorEventHandler. This is the preferred technique for handling the event in a class that is derived from System.Web.UI.WebControls.ChangePassword or System.Web.UI.WebControls.CreateUserWizard.
For more information about handling events, see Server Event Handling in ASP.NET Web Pages.