Bewerken

Share via


CreateUserWizard.MailDefinition Property

Definition

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

public:
 property System::Web::UI::WebControls::MailDefinition ^ MailDefinition { System::Web::UI::WebControls::MailDefinition ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.Themeable(false)]
public System.Web.UI.WebControls.MailDefinition MailDefinition { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.Themeable(false)>]
member this.MailDefinition : System.Web.UI.WebControls.MailDefinition
Public ReadOnly Property MailDefinition As MailDefinition

Property Value

A reference to a MailDefinition object that defines the email message sent to a new user.

Attributes

Exceptions

From is not set to an email address.

Examples

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#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 = e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question);
    e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>",   Createuserwizard1.Answer);  
}
  
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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>
<%@ page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Sub Createuserwizard1_SendingMail(ByVal sender As Object, ByVal e As MailMessageEventArgs)
    ' 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 = e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question)
    e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>",   Createuserwizard1.Answer)
  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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>

Remarks

The MailDefinition property returns a reference to a group of properties that you use to define the format and content of the email 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).

An email message is sent to new users only if MailDefinition is not null and if Body is not empty or null. In that case, the SendingMail event is raised and an attempt is made to send the email message. The From property must be set to an email address. Otherwise, an HttpException exception is thrown.

When the email message is created from the MailDefinition object, it will make the substitutions listed in the following table.

Substitution text Replaced with
<%UserName%> The user name of the newly created user account.
<%Password%> The password for the newly created user account.

If the IsBodyHtml property of the MailDefinition object is true, the contents of the mail message will be HTML encoded to guard against cross-site scripting security vulnerabilities for the message recipient.

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.

Note

It is not possible to guarantee that a user will receive or view an email message. To verify that a user has received a notification by email, consider providing a confirmation link in the email message that enables the user to confirm that the notification was received.

Applies to

See also