MailMessageEventHandler 代理人

定義

表示處理郵件事件的方法。Represents the method that handles mail events.

public delegate void MailMessageEventHandler(System::Object ^ sender, MailMessageEventArgs ^ e);
public delegate void MailMessageEventHandler(object sender, MailMessageEventArgs e);
type MailMessageEventHandler = delegate of obj * MailMessageEventArgs -> unit
Public Delegate Sub MailMessageEventHandler(sender As Object, e As MailMessageEventArgs)

參數

sender
Object

事件的來源。The source of the event.

e
MailMessageEventArgs

MailMessageEventArgs,包含事件的郵件訊息資料。A MailMessageEventArgs that contains the mail message data for the event.

繼承
MailMessageEventHandler

範例

下列程式碼範例會建立 MailMessageEventHandler 實例,以在將電子郵件訊息傳送給收件者之前加以修改。The following code example creates a MailMessageEventHandler instance to modify an email message before sending it to the recipient.

<%@ 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">

  void Page_Init(object sender, EventArgs e)
  {
    PasswordRecoveryOnBeforeSendingEmail passwordRecoveryControl = 
      new PasswordRecoveryOnBeforeSendingEmail();

    passwordRecoveryControl.ID = "passwordRecoveryControl";
    passwordRecoveryControl.MailDefinition.From = "userAdmin@your.site.name.here";
    PlaceHolder1.Controls.Add(passwordRecoveryControl);

  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
    </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_Init(ByVal sender As Object, ByVal e As EventArgs)
    
    Dim passwordRecoveryControl As New PasswordRecoveryOnBeforeSendingEmail
        
    passwordRecoveryControl.ID = "passwordRecoveryControl"
    passwordRecoveryControl.MailDefinition.From = "userAdmin@your.site.name.here"
    PlaceHolder1.Controls.Add(passwordRecoveryControl)
        
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
    </form>
  </body>
</html>

備註

MailMessageEventHandler委派會在將訊息傳送給收件者之前,修改網際網路電子郵件訊息的內容。The MailMessageEventHandler delegate modifies the contents of an Internet email message before the message is sent to the recipients. 例如,您可以新增其他收件者,或使用此處理程式將網站識別為所有訊息的自訂訊息頁尾。For example, you can add additional recipients or a custom message footer identifying your Web site to all messages using this handler.

e參數是一個 MailMessageEventArgs 實例,其中包含屬性中所指定的電子郵件訊息 MessageThe e parameter is a MailMessageEventArgs instance that contains the email message specified in the Message property.

建立 MailMessageEventHandler 委派時,必須識別處理事件的方法。When you create a MailMessageEventHandler delegate, you identify the method that will handle the event. 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。To associate the event with your event handler, add an instance of the delegate to the event. 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。The event handler is called whenever the event occurs, unless you remove the delegate. 如需事件處理常式委派的詳細資訊,請參閱處理和引發事件For more information about event handler delegates, see Handling and Raising Events.

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.

適用於

另請參閱