Export (0) Print
Expand All
Expand Minimize

ChangePassword.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 e-mail message that is sent to users after they have changed their password.

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

The From property 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 sent to users after they have changed their password. Common settings include the subject line and the sender's return address. For a complete list of properties, see MailDefinition.

The MailDefinition property is read-only; however, you can set the properties of the MailDefinition object it returns. You can set these properties 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 e-mail message is sent only if the user has an e-mail address registered with the membership provider and 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.

If the e-mail message is created from the MailDefinition object, it will make the substitutions shown in the following table. The substitution text is case-insensitive.

Substitution text

Replaced with

<% UserName %>

The Web site user name of the user.

<% Password %>

The new password for the user.

You can use the SendingMail event to modify the MailMessage object that is created by the MailDefinition object.

Security noteSecurity Note

Sending user account names or passwords in e-mail is a potential security threat. E-mail messages are typically sent in plain text and can be read by special network "sniffing" applications. To improve security, use the mitigations that are described in Securing Login Controls.

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 shows how to use the MailDefinition property to define an e-mail message that is sent to users who change their passwords. It assumes that there is a file called MailFile.txt that contains the text of the e-mail message to send.

To be able to send e-mail messages to users, you must configure an e-mail server in the Web.config file for your application. For more information, see How to: Install and Configure SMTP Virtual Servers in IIS.

<%@ page language="C#"%>

<script runat="server">
  void Changepassword1_SendingMail(object sender, MailMessageEventArgs e)
  {
    // Set mail message fields.
    e.Message.Subject = "New user on Web site.";
    // Replace placeholder text in message body with
    // information provided by the user.
    e.Message.Body.Replace("<%ChangedDate%>", (DateTime.Now.ToString()) );
  }
</script>

<html>
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:changepassword id="Changepassword1" runat="server" 
        maildefinition-bodyfilename="~/MailFiles/mailfile.txt" 
          maildefinition-from="userAdmin@your.site.name.here" 
          onsendingmail="Changepassword1_SendingMail">
      </asp:changepassword>
    </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:
© 2014 Microsoft