Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (58 sloc) 8.06 KB
<Type Name="SendMailErrorEventHandler" FullName="System.Web.UI.WebControls.SendMailErrorEventHandler">
<TypeSignature Language="C#" Value="public delegate void SendMailErrorEventHandler(object sender, SendMailErrorEventArgs e);" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed SendMailErrorEventHandler extends System.MulticastDelegate" />
<TypeSignature Language="DocId" Value="T:System.Web.UI.WebControls.SendMailErrorEventHandler" />
<TypeSignature Language="VB.NET" Value="Public Delegate Sub SendMailErrorEventHandler(sender As Object, e As SendMailErrorEventArgs)" />
<TypeSignature Language="C++ CLI" Value="public delegate void SendMailErrorEventHandler(System::Object ^ sender, SendMailErrorEventArgs ^ e);" />
<TypeSignature Language="F#" Value="type SendMailErrorEventHandler = delegate of obj * SendMailErrorEventArgs -&gt; unit" />
<Parameter Name="sender" Type="System.Object" />
<Parameter Name="e" Type="System.Web.UI.WebControls.SendMailErrorEventArgs" />
<param name="sender">The source of the event.</param>
<param name="e">A <see cref="T:System.Web.UI.WebControls.SendMailErrorEventArgs" /> object that contains the event data.</param>
<summary>Represents the method that handles the <see langword="SendMailError" /> event of controls such as the <see cref="T:System.Web.UI.WebControls.ChangePassword" /> control, the <see cref="T:System.Web.UI.WebControls.CreateUserWizard" /> control, and the <see cref="T:System.Web.UI.WebControls.PasswordRecovery" /> control.</summary>
<format type="text/markdown"><![CDATA[
## Remarks
When you create a <xref:System.Web.UI.WebControls.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 Forms Pages](
Handling the `SendMailError` event allows your Web application to continue running, even if an exception occurs when trying to send an email 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 <xref:System.Web.UI.WebControls.ChangePassword.SendMailError> event, or if you create an event handler but leave the <xref:System.Web.UI.WebControls.SendMailErrorEventArgs.Handled%2A> 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 <xref:System.Web.UI.WebControls.ChangePassword.OnSendMailError%2A> method also allows derived classes to handle the event instead of the <xref:System.Web.UI.WebControls.SendMailErrorEventHandler>. This is the preferred technique for handling the event in a class that is derived from <xref:System.Web.UI.WebControls.ChangePassword> or <xref:System.Web.UI.WebControls.CreateUserWizard>.
For more information about handling events, see [Server Event Handling in ASP.NET Web Forms Pages](
## Examples
The following code example demonstrates an ASP.NET page that uses a <xref:System.Web.UI.WebControls.ChangePassword> Web control, and includes an event handler for the <xref:System.Web.UI.WebControls.ChangePassword.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 email 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: 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 email message.
If a mail server is not configured correctly or some other error occurs and the email 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 <xref:System.Web.UI.WebControls.SendMailErrorEventArgs.Handled%2A> property of the <xref:System.Web.UI.WebControls.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.
<altmember cref="E:System.Web.UI.WebControls.CreateUserWizard.SendMailError" />
<altmember cref="E:System.Web.UI.WebControls.ChangePassword.SendMailError" />
<altmember cref="E:System.Web.UI.WebControls.PasswordRecovery.SendMailError" />
<altmember cref="T:System.Net.Mail.MailMessage" />
<altmember cref="T:System.Web.Mail.SmtpMail" />
<related type="Article" href="">Server Event Handling in ASP.NET Web Pages</related>
<related type="Article" href="">Handling and Raising Events</related>
<related type="Article" href="~/docs/framework/configure-apps/file-schema/network/">smtp Element (Network Settings)</related>
<related type="Article" href="">Web Site Administration Tool Application Tab</related>
<related type="Article" href="">Securing Login Controls</related>
<related type="Article" href="">Basic Security Practices for Web Applications</related>
You can’t perform that action at this time.