ChangePassword.MailDefinition 属性

定义

获取对一个属性集合的引用,这些属性定义了用户更改其密码后会接收到的电子邮件。Gets a reference to a collection of properties that define the email message that is sent to users after they have changed their password.

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

属性值

MailDefinition

MailDefinition 对象的引用,该对象定义发送给新用户的电子邮件。A reference to a MailDefinition object that defines the email message sent to a new user.

属性

例外

From 属性未设置为电子邮件地址。The From property is not set to an email address.

示例

下面的代码示例演示如何使用 MailDefinition 属性来定义将发送给更改密码的用户的电子邮件。The following code example shows how to use the MailDefinition property to define an email message that is sent to users who change their passwords. 它假定存在一个名为的文件 MailFile.txt ,其中包含要发送的电子邮件的文本。It assumes that there is a file called MailFile.txt that contains the text of the email message to send.

若要能够向用户发送电子邮件,必须在应用程序的 Web.config 文件中配置电子邮件服务器。To be able to send email messages to users, you must configure an email server in the Web.config file for your application. 有关详细信息,请参阅 如何:在 IIS 6.0 中安装和配置 SMTP 虚拟服务器For more information, see How to: Install and Configure SMTP Virtual Servers in IIS 6.0.

<%@ 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 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 = e.Message.Body.Replace("<%ChangedDate%>", (DateTime.Now.ToString()) );
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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>
<%@ 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 Changepassword1_SendingMail(ByVal sender As Object, ByVal e As MailMessageEventArgs)
        ' 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 = e.Message.Body.Replace("<%ChangedDate%>", DateTime.Now.ToString())
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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>

注解

MailDefinition属性返回对一组属性的引用,这些属性用于定义在用户更改其密码后发送给用户的电子邮件的格式和内容。The MailDefinition property returns a reference to a group of properties that you use to define the format and content of the email message sent to users after they have changed their password. 常见设置包括主题行和发件人的寄信人地址。Common settings include the subject line and the sender's return address. 有关完整的属性列表,请参见 MailDefinitionFor a complete list of properties, see MailDefinition.

MailDefinition属性是只读的; 但是,您可以设置它返回的对象的属性 MailDefinitionThe MailDefinition property is read-only; however, you can set the properties of the MailDefinition object it returns. 可以在 "窗体 属性" 子属性中设置这些属性,其中,子属性 - 表示类的属性 MailDefinition (例如 MailDefinition-Subject) 。You can set these properties in the form property-subproperty, where subproperty represents a property of the MailDefinition class (for example, MailDefinition-Subject). 还可以在窗体 属性 子属性中以编程方式设置属性 . (例如 MailDefinition.Subject) 。You can also set the properties programmatically in the form Property.Subproperty (for example,MailDefinition.Subject).

仅当用户具有使用成员资格提供程序注册的电子邮件地址,并且 BodyFileName 属性的属性指向有效文件时,才会发送电子邮件 MailDefinitionAn email message is sent only if the user has an email address registered with the membership provider and if the BodyFileName property of the MailDefinition property points to a valid file. 如果 BodyFileName 设置了属性,则 From 必须将属性设置为电子邮件地址; 否则,将 HttpException 引发异常。If the BodyFileName property is set, the From property must be set to an email address; otherwise, an HttpException exception is thrown.

如果电子邮件是从对象创建的 MailDefinition ,它将进行下表中所示的替换。If the email 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 %><% UserName %> 用户的网站用户名。The Web site user name of the user.
<% Password %> 用户的新密码。The new password for the user.

如果 IsBodyHtml 对象的属性为,则将对邮件的 MailDefinition true 内容进行 HTML 编码,以防邮件收件人出现跨站点脚本安全漏洞。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.

可以使用 SendingMail 事件修改 MailMessage 对象创建的对象 MailDefinitionYou can use the SendingMail event to modify the MailMessage object that is created by the MailDefinition object.

重要

在电子邮件中发送用户帐户名或密码是潜在的安全威胁。Sending user account names or passwords in email is a potential security threat. 电子邮件通常以纯文本方式发送,可由特殊网络 "探查" 应用程序读取。Email 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. 有关详细信息,请参阅 ThemeableAttributeASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

适用于