共用方式為


CreateUserWizard.OnSendMailError(SendMailErrorEventArgs) 方法

定義

當電子郵件無法傳送至新使用者時,引發 SendMailError 事件。

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

參數

e
SendMailErrorEventArgs

包含事件資料的 SendMailErrorEventArgs

範例

下列程式代碼範例會定義自定義 CreateUserWizard 物件,以將電子郵件錯誤記錄至網站特定的記錄函式。

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls {

  [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  public class CustomCreateUserWizard : CreateUserWizard
  {
    private void SiteSpecificErrorLoggingProcedure (SendMailErrorEventArgs e)
    {
      // Site-specific code for logging email errors goes here.
    }

    protected override void OnSendMailError (SendMailErrorEventArgs e)
    {
      this.SiteSpecificErrorLoggingProcedure (e);
      e.Handled = true;
    }
  }
}
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
  <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class CustomCreateUserWizard
    Inherits CreateUserWizard

    Private Sub SiteSpecificErrorLoggingProcedure(ByVal e As SendMailErrorEventArgs)
      ' Site-specific code for logging email errors goes here.
    End Sub
    
    Overloads Sub OnSendMailError(ByVal e As SendMailErrorEventArgs)
      Me.SiteSpecificErrorLoggingProcedure(e)
      e.Handled = True
    End Sub
  End Class
End Namespace

下列程式代碼範例示範使用 的 CustomCreateUserWizard網頁。

<%@ 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_Load (object sender, EventArgs e)
  {
    CustomCreateUserWizard createUser = new CustomCreateUserWizard ();
    Placeholder1.Controls.Add (createUser);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUserWizard.OnSendMailError 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 System.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.OnSendMailError sample</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:placeholder id="Placeholder1" runat="server">
        </asp:placeholder>
      </div>
    </form>
  </body>
</html>

備註

OnSendMailError當 SMTP 郵件系統嘗試傳送電子郵件給新使用者時,會呼叫 方法。

Exception檢查傳遞為 e 參數之 對象的 屬性,SendMailErrorEventArgs以判斷例外狀況的實際原因。 最常見的問題是 Web.config 檔案區段中的組態錯誤 <smtpMail>

您必須將傳遞的物件 屬性SendMailErrorEventArgs設定Handlede 參數,以表示已處理導致OnSendMailError呼叫方法的例外狀況,否則會重新擲回例外狀況。

引發事件會透過委派叫用此事件處理常式。 如需詳細資訊,請參閱 處理和引發事件

OnSendMailError 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。

給繼承者的注意事項

OnSendMailError(SendMailErrorEventArgs) 衍生類別中覆寫時,請務必呼叫基類的 OnSendMailError(SendMailErrorEventArgs) 方法,讓已註冊的委派接收事件。

適用於

另請參閱