CreateUserWizard.SendingMail 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在向用户发送用于确认帐户已创建的电子邮件前发生。
public:
event System::Web::UI::WebControls::MailMessageEventHandler ^ SendingMail;
public event System.Web.UI.WebControls.MailMessageEventHandler SendingMail;
member this.SendingMail : System.Web.UI.WebControls.MailMessageEventHandler
Public Custom Event SendingMail As MailMessageEventHandler
事件类型
示例
下面的代码示例使用 SendingMail 事件修改发送给新用户的电子邮件。 此示例需要包含以下文本的名为 MailFile.txt 的文本文件。
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>
注解
当 CreateUserWizard 属性定义要发送的电子邮件时, MailDefinition 类将发送电子邮件,确认已创建新的网站帐户。
由于电子邮件只有用户名和密码字段的自动替换字段,因此可以使用 SendingMail 事件修改电子邮件,然后再将其发送给新用户。
有关如何处理事件的详细信息,请参阅 处理和引发事件。