SendMailErrorEventHandler 대리자

정의

ChangePassword 컨트롤, CreateUserWizard 컨트롤, PasswordRecovery 컨트롤과 같은 컨트롤의 SendMailError 이벤트를 처리하는 메서드를 나타냅니다.

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

매개 변수

sender
Object

이벤트 소스입니다.

e
SendMailErrorEventArgs

이벤트 데이터를 포함하는 SendMailErrorEventArgs 개체입니다.

예제

다음 코드 예제를 사용 하는 ASP.NET 페이지를 보여 줍니다.는 ChangePassword 웹 컨트롤 및 이벤트 처리기를 포함 합니다 SendMailError 라는 이벤트 SendMailError합니다. 코드 예제에서는 ASP.NET 멤버 자격 및 폼 인증 및 사용자가 만들어졌는지 해당 이름 및 암호를 알고 사용 하 여 ASP.NET 웹 사이트를 구성한 경우를 가정 합니다. 자세한 내용은 방법: 간단한 폼 인증 구현합니다.

암호 변경에 성공 하는 경우에 코드 변경 확인을 위해 사용자에 게 전자 메일 메시지를 보낼 SMTP를 사용 하려고 합니다. 이 수행 된 SendingMail 이벤트 처리기입니다. SMTP 서버를 구성하는 방법에 대한 자세한 내용은 방법: IIS 6.0에서 SMTP 가상 서버 설치 및 구성을 참조하세요. 이 예제에서는 필요 없는 SMTP 서버를 구성 하려면 이 예제에서는 전자 메일 메시지를 보내는 오류에 대 한 테스트에 생성 됩니다.

메일 서버가 올바르게 구성 되지 않았습니다. 또는 다른 오류가 발생 하 고 전자 메일 메시지를 보낼 수 없는 경우는 SendMailError 함수를 호출 합니다. 사용자에 게 메시지가 표시 됩니다. 또한 이벤트는 이미 MySamplesSite 라는 이벤트 소스가 있는지 가정을 사용 하 여 Windows 애플리케이션 이벤트 로그에 기록 됩니다. 지정된 된 이벤트 소스를 만들려면 다음 코드 예제를 참조 하세요. 이벤트 소스를 만드는 방법에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지에서 서버 이벤트 처리합니다. 합니다 Handled 의 속성을 SendMailErrorEventArgs 개체로 설정 됩니다 true 오류가 처리 된 것을 나타내기 위해.

<%@ Page Language="C#" AutoEventWireup="True" %>

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

  void MySendingMail(object sender, MailMessageEventArgs e)
  {
    Message1.Text = "Sent mail to you to confirm the password change.";
  }

  void MySendMailError(object sender, SendMailErrorEventArgs e)
  {
    Message1.Text = "Could not send email to confirm password change.";

    // The MySamplesSite event source has already been created by an administrator.
    System.Diagnostics.EventLog myLog = new System.Diagnostics.EventLog();
    myLog.Log = "Application";
    myLog.Source = "MySamplesSite";
    myLog.WriteEntry(
        "Sending mail via SMTP failed with the following error: " + 
        e.Exception.Message.ToString(), 
        System.Diagnostics.EventLogEntryType.Error);

    e.Handled = true;
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true"
      OnSendingMail="MySendingMail" 
      OnSendMailError="MySendMailError" 
      ContinueDestinationPageUrl="~/Default.aspx" >
      <MailDefinition 
        BodyFileName="~\MailFiles\ChangePasswordMail.htm" 
        Subject="Activity information for you">
        <EmbeddedObjects>
          <asp:EmbeddedMailObject Name="LoginGif" Path="~\MailFiles\Login.gif" />
          <asp:EmbeddedMailObject Name="PrivacyNoticeTxt" Path="~\MailFiles\PrivacyNotice.txt" />
        </EmbeddedObjects>
      </MailDefinition>
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

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

<script runat="server">

  Public Sub MySendingMail(ByVal Sender As Object, ByVal e As MailMessageEventArgs)
    Message1.Text = "Sent mail to you to confirm the password change."
  End Sub

  Public Sub MySendMailError(ByVal Sender As Object, ByVal e As SendMailErrorEventArgs)
    Message1.Text = "Could not send mail to confirm the password change."
    
    ' The MySamplesSite event source has already been created by an administrator.
    Dim myLog As System.Diagnostics.EventLog
    myLog = new System.Diagnostics.EventLog
    myLog.Log = "Application"
    myLog.Source = "MySamplesSite"
    myLog.WriteEntry("Sending mail via SMTP failed with the following error: " & e.Exception.Message.ToString(), System.Diagnostics.EventLogEntryType.Error)

    e.Handled = True
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true"
      OnSendingMail="MySendingMail" 
      OnSendMailError="MySendMailError" 
      ContinueDestinationPageUrl="~/Default.aspx" >
      <MailDefinition 
        BodyFileName="~\MailFiles\ChangePasswordMail.htm" 
        Subject="Activity information for you">
        <EmbeddedObjects>
          <asp:EmbeddedMailObject Name="LoginGif" Path="~\MailFiles\Login.gif" />
          <asp:EmbeddedMailObject Name="PrivacyNoticeTxt" Path="~\MailFiles\PrivacyNotice.txt" />
        </EmbeddedObjects>
      </MailDefinition>
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>

프로그래밍 방식으로 애플리케이션 로그에 MySamplesSite 라는 이벤트 소스를 추가 해야 하는 경우 다음 코드 예제를 사용 합니다. 이 이벤트 소스는 제대로 작동 하려면 첫 번째 코드 예제에 대 한 순서로 존재 해야 합니다. 다음 코드 예제에는 관리자 권한이 필요합니다.

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

#endregion

namespace CreateEventSource
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
                // Create the source, if it does not already exist.
                if (!EventLog.SourceExists("MySamplesSite"))
                {
                    EventLog.CreateEventSource("MySamplesSite", "Application");
                    Console.WriteLine("Creating Event Source");
                }

                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "MySamplesSite";

                // Write an informational entry to the event log.    
                myLog.WriteEntry("Testing writing to event log.");

                Console.WriteLine("Message written to event log.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception:");
                Console.WriteLine("{0}", e.ToString());
            }
        }
    }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Diagnostics


Namespace CreateEventSource
  Class Program
    Sub Main()

        Try
            ' Create the source, if it does not already exist.
            If Not (EventLog.SourceExists("MySamplesSite")) Then
                EventLog.CreateEventSource("MySamplesSite", "Application")
                Console.WriteLine("Creating Event Source")
            End If

            ' Create an EventLog instance and assign its source.
            Dim myLog As New EventLog
            myLog.Source = "MySamplesSite"

            ' Write an informational entry to the event log.
            myLog.WriteEntry("Testing writing to event log.")

            Console.WriteLine("Message written to event log.")
        Catch e As Exception
            Console.WriteLine("Exception:")
            Console.WriteLine(e.ToString)
        End Try

    End Sub
  End Class
End Namespace

설명

SendMailErrorEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기를 연결 하려면 이벤트 대리자의 인스턴스를 추가 합니다. 이벤트의 대리자를 제거 하지 않으면 이벤트가 발생할 때마다 이벤트 처리기가 호출 됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지에서 서버 이벤트 처리합니다.

처리는 SendMailError 이벤트를 사용 하면 웹 애플리케이션을 전자 메일 메시지를 보내려고 할 때 예외가 발생 하는 경우에 실행을 계속 합니다. 예를 들어,이 다중 단계 마법사를 통해 사용자가 작업 하는 동안 예외가 발생 하는 경우에 유용 합니다. 오류를 기록, 정보 메시지를 사용자에 게 표시 및 사용자가 애플리케이션을 종료 하지 않고 마법사를 완료 하도록 허용 하는 것이 좋습니다.

이벤트 처리기를 만들지 않도록 하는 경우는 SendMailError 이벤트를 쓰여 졌지만 이벤트 처리기를 만드는 경우 또는 합니다 Handled 속성으로 설정 false, 웹 애플리케이션의 전자 메일 메시지를 보낼 때 오류가 발생 하면 실행이 중지 됨 및 ASP.NET은 오류 메시지를 표시 합니다.

합니다 OnSendMailError 메서드 대신 이벤트를 처리 하기 위해 파생된 클래스에서는 SendMailErrorEventHandler합니다. 파생 된 클래스에서 이벤트를 처리 하는 기본 방법 이것이 ChangePassword 또는 CreateUserWizard합니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지에서 서버 이벤트 처리합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보