Share via


CreateUserWizard.OnSendingMail(MailMessageEventArgs) 方法

定义

向新用户发送电子邮件前引发 SendingMail 事件。

protected:
 virtual void OnSendingMail(System::Web::UI::WebControls::MailMessageEventArgs ^ e);
protected virtual void OnSendingMail (System.Web.UI.WebControls.MailMessageEventArgs e);
abstract member OnSendingMail : System.Web.UI.WebControls.MailMessageEventArgs -> unit
override this.OnSendingMail : System.Web.UI.WebControls.MailMessageEventArgs -> unit
Protected Overridable Sub OnSendingMail (e As MailMessageEventArgs)

参数

e
MailMessageEventArgs

包含事件数据的 MailMessageEventArgs

示例

下面的代码示例定义了一个自定义 CreateUserWizard 控件,该控件使用 OnSendingMail 方法修改发送给新用户的电子邮件的文本。 此示例需要一个名为 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#"%>
<%@ Import namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(object sender, EventArgs e) {    
    Placeholder1.Controls.Add(new CustomCreateUserWizard());
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>CreateUserWizard.OnSendingMail sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:placeholder id="Placeholder1" runat="server" >
      </asp:placeholder>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB"%>
<%@ Import namespace="Samples.AspNet.VB.Controls" %>

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

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim createUser As New CustomCreateUserWizard
    Placeholder1.Controls.Add(createUser)
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUserWizard.OnSendingMail sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:placeholder id="Placeholder1" runat="server" >
      </asp:placeholder>
    </div>
    </form>
</body>
</html>

注解

OnSendingMail使用 方法修改发送给新用户的电子邮件。 Message作为 e 参数传递的 MailMessageEventArgs 对象的 属性包含MailMessage将发送给新用户的 对象。 修改 对象的属性 MailMessage 以修改电子邮件。

仅当 属性指定的 MailDefinition 对象的 属性MailDefinition指向有效的文件名时BodyFileName,才会创建Email消息。

引发事件时,将通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件

OnSendingMail 方法还允许派生类对事件进行处理而不必附加委托。 这是在派生类中处理事件的首选技术。

继承者说明

在派生类中重写 OnSendingMail(MailMessageEventArgs) 时,请务必调用基类的 OnSendingMail(MailMessageEventArgs) 方法,以便注册的委托接收 事件。

适用于

另请参阅