CreateUserWizard.OnSendingMail Method

Note: This method is new in the .NET Framework version 2.0.

Raises the SendingMail event before an e-mail message is sent to a new user.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

protected virtual void OnSendingMail (
	MailMessageEventArgs e
protected void OnSendingMail (
	MailMessageEventArgs e
protected function OnSendingMail (
	e : MailMessageEventArgs



A MailMessageEventArgs containing the event data.

Use the OnSendingMail method to modify the e-mail message sent to new users. The Message property of the MailMessageEventArgs object passed as the e parameter contains the MailMessage object that will be sent to the new user. Modify the properties of the MailMessage object to modify the e-mail message.

E-mail messages are only created when the BodyFileName property of the MailDefinition object specified by the MailDefinition property points to a valid file name.

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

The OnSendingMail 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 OnSendingMail in a derived class, be sure to call the base class’s OnSendingMail method so that registered delegates receive the event.

The following code example defines a custom CreateUserWizard control that uses the OnSendingMail method to modify the text of the e-mail sent to new users. This example requires a text file named MailFile.txt that contains the following text.

Your account was set up on our Web site with the following:

    Username:   <%UserName%>

To reset your password, you must answer the following question:

    Password Question: <%PasswordQuestion%>  
    Password Answer:   <%PasswordAnswer%>  
Thank you for creating an account with our Web site.
<%@ Page Language="C#"%>
<%@ Import namespace="Samples.AspNet.CS.Controls" %>

<script runat="server">
private void Page_Load(object sender, EventArgs e) {    
    Placeholder1.Controls.Add(new CustomCreateUserWizard());

<head id="Head1" runat="server">
    <title>CreateUserWizard.OnSendingMail sample</title>
    <form id="form1" runat="server">
      <asp:placeholder id="Placeholder1" runat="server" >

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions