This documentation is archived and is not being maintained.

CreateUserWizard.MailDefinition Property

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

Gets a reference to a collection of properties that define the characteristics of the e-mail message sent to new users.

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

[ThemeableAttribute(false)] 
public MailDefinition MailDefinition { get; }
/** @property */
public MailDefinition get_MailDefinition ()

public function get MailDefinition () : MailDefinition

Property Value

A reference to a MailDefinition object that defines the e-mail message sent to a new user.

Exception typeCondition

HttpException

From is not set to an e-mail address.

The MailDefinition property returns a reference to a group of properties that you use to define the format and content of the e-mail message that is sent to new users. Common settings include the subject line and the sender's return address. For a complete list of properties, see the MailDefinition class.

The MailDefinition property is read-only; however, you can set the properties of the MailDefinition object it returns. You can set the MailDefinition properties declaratively in the form Property-Subproperty, where Subproperty represents a property of the MailDefinition class (for example, MailDefinition-Subject). You can also set the properties programmatically in the form Property.SubProperty (for example, MailDefinition.Subject).

E-mail is only sent to new users if the BodyFileName property of the MailDefinition property points to a valid file. If the BodyFileName property is set, the From property must be set to an e-mail address. Otherwise, an HttpException exception is thrown.

When the e-mail message is created from the MailDefinition object, it will make the following substitutions.

Substitution text

Replaced with

<%UserName%>

The user name of the newly created user account.

<%Password%>

The password for the newly created user account.

You can use the OnSendingMail method to modify the MailMessage created by the MailDefinition object.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

The following code example sets properties of the MailDefinition property by using both declarative and programmatic syntax. This code 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
Show: