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

包含事件的邮件数据的 MailMessageEventArgsA MailMessageEventArgs that contains the mail message data for the event.

示例

下面的代码示例创建一个 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委托在将邮件发送给收件人之前修改 Internet 电子邮件的内容。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. 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。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.

适用于

另请参阅