SendMailErrorEventArgs Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides data for the SendMailError
event of controls such as the ChangePassword control, the CreateUserWizard control, and the PasswordRecovery control.
public ref class SendMailErrorEventArgs : EventArgs
public class SendMailErrorEventArgs : EventArgs
type SendMailErrorEventArgs = class
inherit EventArgs
Public Class SendMailErrorEventArgs
Inherits EventArgs
- Inheritance
Remarks
The SendMailErrorEventArgs object contains an error message that is raised by the SMTP mail provider when an email message cannot be sent by the ChangePassword control, or the CreateUserWizard control. In such a case, the SendMailErrorEventArgs object is sent to the SendMailErrorEventHandler.
Create a 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 email 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 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 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 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 email message, and ASP.NET will display an error message.
The OnSendMailError method also allows derived classes to handle the event, instead of this being done by 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 Forms Pages.
Notes to Inheritors
When overriding OnSendMailError(SendMailErrorEventArgs) in a derived class, be sure to call the OnSendMailError(SendMailErrorEventArgs) method of the base class to enable registered delegates to receive the event.
Constructors
SendMailErrorEventArgs(Exception) |
Initializes a new instance of the SendMailErrorEventArgs class. |
Properties
Exception |
Returns the exception thrown by an SMTP mail service when an email message cannot be sent. |
Handled |
Indicates if the SMTP exception that is contained in the Exception property has been handled. |
Methods
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |