Skip to content
Permalink
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" />
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Delegate</BaseTypeName>
</Base>
<Parameters>
<Parameter Name="sender" Type="System.Object" />
<Parameter Name="e" Type="System.Web.UI.WebControls.SendMailErrorEventArgs" />
</Parameters>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Docs>
<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>
<remarks>
<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](https://msdn.microsoft.com/library/765bfc89-33ee-4d0d-bbe6-3b172c06def9).
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](https://msdn.microsoft.com/library/765bfc89-33ee-4d0d-bbe6-3b172c06def9).
## 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](https://msdn.microsoft.com/library/9522bc8d-1a41-480a-aa11-c389a4ac2d2e).
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](https://docs.microsoft.com/previous-versions/aspnet/8b83ac7t(v=vs.100)). 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](https://msdn.microsoft.com/library/765bfc89-33ee-4d0d-bbe6-3b172c06def9). 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.
[!code-aspx-csharp[System.Web.UI.WebControls.SendMailErrorEventHandler#1](~/samples/snippets/csharp/VS_Snippets_WebNet/System.Web.UI.WebControls.SendMailErrorEventHandler/CS/changepassword_cs.aspx#1)]
[!code-aspx-vb[System.Web.UI.WebControls.SendMailErrorEventHandler#1](~/samples/snippets/visualbasic/VS_Snippets_WebNet/System.Web.UI.WebControls.SendMailErrorEventHandler/VB/changepassword_vb.aspx#1)]
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.
[!code-csharp[System.Diagnostics.EventLog.CreateEventSource#1](~/samples/snippets/csharp/VS_Snippets_WebNet/System.Diagnostics.EventLog.CreateEventSource/CS/createeventsource.cs#1)]
[!code-vb[System.Diagnostics.EventLog.CreateEventSource#1](~/samples/snippets/visualbasic/VS_Snippets_WebNet/System.Diagnostics.EventLog.CreateEventSource/VB/createeventsource.vb#1)]
]]></format>
</remarks>
<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="https://msdn.microsoft.com/library/765bfc89-33ee-4d0d-bbe6-3b172c06def9">Server Event Handling in ASP.NET Web Pages</related>
<related type="Article" href="https://msdn.microsoft.com/library/b6f65241-e0ad-4590-a99f-200ce741bb1f">Handling and Raising Events</related>
<related type="Article" href="~/docs/framework/configure-apps/file-schema/network/smtp-element-network-settings.md">smtp Element (Network Settings)</related>
<related type="Article" href="https://msdn.microsoft.com/library/448f7802-0aa8-4304-abf7-82e138877dc8">Web Site Administration Tool Application Tab</related>
<related type="Article" href="https://msdn.microsoft.com/library/d85075bc-9c1a-4453-8a0c-539b10853c9c">Securing Login Controls</related>
<related type="Article" href="https://msdn.microsoft.com/library/3eeeee9e-b09f-4c7f-8ce5-d9ca1f9322ad">Basic Security Practices for Web Applications</related>
</Docs>
</Type>
You can’t perform that action at this time.