Uređivanje

Dijeli putem


CreateUserWizard.OnSendingMail(MailMessageEventArgs) Method

Definition

Raises the SendingMail event before an email message is sent to a new user.

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)

Parameters

e
MailMessageEventArgs

A MailMessageEventArgs containing the event data.

Examples

The following code example defines a custom CreateUserWizard control that uses the OnSendingMail method to modify the text of the email sent to new users. This example requires a text file named MailFile.txt that contains the following text.

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>

Remarks

Use the OnSendingMail method to modify the email message sent to new users. The Message property of the MailMessageEventArgs object passed as the e parameter contains the MailMessage object that will be sent to the new user. Modify the properties of the MailMessage object to modify the email message.

Email messages are only created when the BodyFileName property of the MailDefinition object specified by the MailDefinition property points to a valid file name.

Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.

The OnSendingMail method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors

When overriding OnSendingMail(MailMessageEventArgs) in a derived class, be sure to call the base class' OnSendingMail(MailMessageEventArgs) method so that registered delegates receive the event.

Applies to

See also