ChangePassword.MailDefinition 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对一个属性集合的引用,这些属性定义了用户更改其密码后会接收到的电子邮件。
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 对象的引用,该对象定义发送给新用户的电子邮件。
- 属性
例外
From 属性未设置为电子邮件地址。
示例
下面的代码示例演示如何使用 MailDefinition 属性定义发送给更改其密码的用户的电子邮件。 它假定有一个名为 MailFile.txt
的文件,其中包含要发送的电子邮件的文本。
若要能够向用户发送电子邮件,必须在应用程序的 Web.config 文件中配置电子邮件服务器。 有关详细信息,请参阅 如何:在 IIS 6.0 中安装和配置 SMTP 虚拟服务器。
<%@ 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 返回对一组属性的引用,这些属性用于定义在用户更改密码后发送给用户的电子邮件的格式和内容。 常见设置包括主题行和发件人的寄信人地址。 有关完整的属性列表,请参见 MailDefinition。
属性 MailDefinition 是只读的;但是,您可以设置它返回的对象 MailDefinition 的属性。 可以在窗体 属性-
子属性中设置这些属性,其中 子属性 表示 MailDefinition 类的属性 (例如 MailDefinition-Subject
,) 。 还可以以编程方式以 属性.
子属性 的形式设置属性 (例如,MailDefinition.Subject
) 。
仅当用户的电子邮件地址已注册到成员资格提供程序,并且 BodyFileName 属性的 MailDefinition 属性指向有效的文件时,才会发送电子邮件。 BodyFileName如果设置了 属性,则必须将 From 属性设置为电子邮件地址;否则,HttpException将引发异常。
如果电子邮件是从 对象创建的 MailDefinition ,它将进行下表所示的替换。 替换文本不区分大小写。
替换文本 | 替换为 |
---|---|
<%UserName %> |
用户的网站用户名。 |
<%Password%> | 用户的新密码。 |
IsBodyHtml如果 对象的 属性MailDefinition为 true
,则邮件内容将采用 HTML 编码,以防止邮件收件人的跨站点脚本安全漏洞。
可以使用 SendingMail 事件修改 MailMessage 由 对象创建的对象 MailDefinition 。
重要
在电子邮件中发送用户帐户名或密码是潜在的安全威胁。 Email消息通常以纯文本形式发送,可由特殊网络“探查”应用程序读取。 若要提高安全性,请使用 保护登录控件中所述的缓解措施。
无法通过主题或样式表主题设置此属性。 有关详细信息,请参阅 ThemeableAttribute 和 ASP.NET 主题和皮肤。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈