<asp:passwordrecovery>如何自定义发送给用户的电子邮件?</asp:passwordrecovery>

时间:2010-05-14 15:16:52

标签: asp.net asp.net-membership password-recovery customising

我目前在ASP.NET中设置了一个基本会员系统并使用了

<asp:PasswordRecovery ID="PasswordRecovery1" Runat="server"></asp:PasswordRecovery>

要处理密码恢复,哪个工作得很好但是如何自定义电子邮件,例如更改“主题”和电子邮件的实际正文内容?

3 个答案:

答案 0 :(得分:6)

为密码恢复控件实施 OnSendingMail 事件。

参数(MailMessageEventArgs e)是MailMessage对象,您可以在实际发送消息之前更新主题/正文等字段。

答案 1 :(得分:2)

您可以修改MailDefinition设置。

MailDefinition-BodyFileName="uri"
MailDefinition-CC="string"
MailDefinition-From="string"
MailDefinition-IsBodyHtml="True|False"
MailDefinition-Priority="Normal|Low|High"
MailDefinition-Subject="string"

答案 2 :(得分:1)

请在此链接中查看David Winchester的回答 https://forums.asp.net/post/3167737.aspx

我对他的回答进行了如下编辑:

<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
        <MailDefinition 
            From="noreply@gmail.com" 
            Subject="Your temporary password!" 
            IsBodyHtml="true" 
            Priority="High" 
            BodyFileName="~/Templates/PasswordRecoveryMail.htm">
        </MailDefinition>
    </asp:PasswordRecovery>

PasswordRecoveryMail.htm文件的内容

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <div>
        Please return to the site and log in using the following information. 
    </div>
<p>Username: <%UserName%></p>
    <p>Password: <%Password%></p>
</body>
</html>
相关问题