CreateUserWizard.SendingMail Event

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

Occurs before the user is sent an e-mail confirmation that an account has been created.

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

public event MailMessageEventHandler SendingMail
/** @event */
public void add_SendingMail (MailMessageEventHandler value)

/** @event */
public void remove_SendingMail (MailMessageEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The CreateUserWizard class will send an e-mail message confirming that a new Web site account has been created when the MailDefinition property defines an e-mail message to send.

Because the e-mail message only has automatic replacement fields for the user name and password fields, you can use the SendingMail event to modify the e-mail message before it is sent to the new user.

For more information about handling events, see Consuming Events.

The following code example uses the SendingMail event to modify the e-mail message that is 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#"%>
<script runat="server">
  void Createuserwizard1_SendingMail(object sender, MailMessageEventArgs e)
  {
    // Set MailMessage fields.
    e.Message.IsBodyHtml = false;
    e.Message.Subject = "New user on Web site.";
    // Replace placeholder text in message body with information 
    // provided by the user.
    e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question);
    e.Message.Body.Replace("<%PasswordAnswer%>",   Createuserwizard1.Answer);
  }
  
</script>
<html>
  <head runat="server">
    <title>
      CreateUserWizard.MailDefinition sample</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:createuserwizard id="Createuserwizard1" runat="server" 
          maildefinition-bodyfilename="MailFile.txt"
          maildefinition-from="userAdmin@your.site.name.here" 
          onsendingmail="Createuserwizard1_SendingMail">
        </asp:createuserwizard>
      </div>
    </form>
  </body>
</html>

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

ADD
Show: