SendMailErrorEventArgs.Exception Property
Assembly: System.Web (in system.web.dll)
/** @property */ public Exception get_Exception () /** @property */ public void set_Exception (Exception value)
public function get Exception () : Exception public function set Exception (value : Exception)
Not applicable.
Property Value
An Exception object that contains the exception.The Exception property contains the exception that is thrown by the SMTP mail provider when an e-mail message cannot be sent by the ChangePassword control or the CreateUserWizard. The most common reason for this exception is a configuration error in the smtp Element (Network Settings) of the machine configuration file, which produces the following exception message: The transport failed to connect to the server.
Exceptions are not thrown if there is an error in the e-mail message when embedding a file using EmbeddedObjects. Instead, the embedded file appears broken when the mail message is viewed.
You must set the Handled object, passed as the e parameter of SendMailErrorEventArgs, to true to signal that the exception has been handled; otherwise, the exception is rethrown, and includes the original call stack and error message.
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 in the SendingMail event handler attempts to send an e-mail message to the user to confirm the change. SMTP must already be configured on the server in order for this code example to work. 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.
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.
Reference
SendMailErrorEventArgs ClassSendMailErrorEventArgs Members
System.Web.UI.WebControls Namespace
CreateUserWizard.SendMailError Event
ChangePassword.SendMailError Event
PasswordRecovery.SendMailError Event
MailMessage
Other Resources
Server Event Handling in ASP.NET Web PagesHandling and Raising Events
Web Site Administration Tool Application Tab