Bewerken

Delen via


CreateUserWizard.OnSendMailError(SendMailErrorEventArgs) Method

Definition

Raises the SendMailError event when email cannot be sent to the new user.

protected:
 virtual void OnSendMailError(System::Web::UI::WebControls::SendMailErrorEventArgs ^ e);
protected virtual void OnSendMailError (System.Web.UI.WebControls.SendMailErrorEventArgs e);
abstract member OnSendMailError : System.Web.UI.WebControls.SendMailErrorEventArgs -> unit
override this.OnSendMailError : System.Web.UI.WebControls.SendMailErrorEventArgs -> unit
Protected Overridable Sub OnSendMailError (e As SendMailErrorEventArgs)

Parameters

e
SendMailErrorEventArgs

A SendMailErrorEventArgs containing the event data.

Examples

The following code example defines a custom CreateUserWizard object that logs email errors to a site-specific logging function.

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls {

  [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  public class CustomCreateUserWizard : CreateUserWizard
  {
    private void SiteSpecificErrorLoggingProcedure (SendMailErrorEventArgs e)
    {
      // Site-specific code for logging email errors goes here.
    }

    protected override void OnSendMailError (SendMailErrorEventArgs e)
    {
      this.SiteSpecificErrorLoggingProcedure (e);
      e.Handled = true;
    }
  }
}
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
  <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class CustomCreateUserWizard
    Inherits CreateUserWizard

    Private Sub SiteSpecificErrorLoggingProcedure(ByVal e As SendMailErrorEventArgs)
      ' Site-specific code for logging email errors goes here.
    End Sub
    
    Overloads Sub OnSendMailError(ByVal e As SendMailErrorEventArgs)
      Me.SiteSpecificErrorLoggingProcedure(e)
      e.Handled = True
    End Sub
  End Class
End Namespace

The following code example demonstrates a Web page that uses the CustomCreateUserWizard.

<%@ Page Language="C#"%>
<%@ Import namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  void Page_Load (object sender, EventArgs e)
  {
    CustomCreateUserWizard createUser = new CustomCreateUserWizard ();
    Placeholder1.Controls.Add (createUser);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUserWizard.OnSendMailError sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:placeholder id="Placeholder1" runat="server">
      </asp:placeholder>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB"%>
<%@ Import namespace="Samples.AspNet.VB.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim createUser As New CustomCreateUserWizard
    Placeholder1.Controls.Add(createUser)
  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      CreateUserWizard.OnSendMailError sample</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:placeholder id="Placeholder1" runat="server">
        </asp:placeholder>
      </div>
    </form>
  </body>
</html>

Remarks

The OnSendMailError method is called when the SMTP mail system raises an exception while attempting to send email to the new user.

Examine the Exception property of the SendMailErrorEventArgs object passed as the e parameter to determine the actual cause of the exception. The most common problem is a configuration error in the <smtpMail> section of the Web.config file.

You must set the Handled property of the SendMailErrorEventArgs object passed as the e parameter to signal that the exception that caused the OnSendMailError method to be called has been taken care of, otherwise the exception is re-thrown.

Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.

The OnSendMailError method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors

When overriding OnSendMailError(SendMailErrorEventArgs) in a derived class, be sure to call the base class' OnSendMailError(SendMailErrorEventArgs) method so that registered delegates receive the event.

Applies to

See also