SendMailErrorEventArgsとは? わかりやすく解説

SendMailErrorEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ChangePassword、CreateUserWizard、PasswordRecovery など各コントロールSendMailError イベントデータ提供します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class SendMailErrorEventArgs
    Inherits EventArgs
Dim instance As SendMailErrorEventArgs
public class SendMailErrorEventArgs : EventArgs
public ref class SendMailErrorEventArgs : public
 EventArgs
public class SendMailErrorEventArgs extends
 EventArgs
public class SendMailErrorEventArgs extends
 EventArgs
解説解説

SendMailErrorEventArgs オブジェクトには、ChangePassword コントロールまたは CreateUserWizard コントロールによって送信され電子メール メッセージ送信できない場合SMTP メール プロバイダ作成するエラー メッセージ含まれています。そのような場合SendMailErrorEventArgs オブジェクトが SendMailErrorEventHandler に渡されます。

イベント処理するには、SendMailErrorEventHandler デリゲート作成しますイベント処理することで、例外発生した場合でも Web アプリケーション実行継続できます。これは、電子メール メッセージの送信が重要ではないアプリーケーションで便利です。たとえば、ユーザー複数の手順で構成されるウィザード操作しているときに例外発生した場合は、そのエラー記録し情報メッセージユーザー表示してユーザーウィザード完了できるようにした方が好都合です。

例外実際の原因確認するには、Exception プロパティ調べます例外の最も一般的な原因は、コンピュータ構成ファイルsmtp 要素 (ネットワーク設定) の設定ミスです。このようなエラーは、通常アプリケーション開発およびデバッグ中に検出されますが、メール サーバー予期しないエラー発生することがあるため、そのような場合アプリケーション全体エラーにするかどうか決定する必要がありますそうしない場合は、イベント処理することでアプリケーション続行できます

Handled プロパティtrue設定して例外処理されたことを通知する必要がありますそうしない場合例外再度スローされ、その例外には元のコール スタックエラー メッセージ含まれます。

SendMailError イベントイベント ハンドラ作成してない場合、またはイベント ハンドラ作成してHandled プロパティfalse設定されたままになっている場合電子メール メッセージの送信時にエラー発生すると、Web アプリケーション実行停止しASP.NET によってエラー メッセージ表示されます。

OnSendMailError メソッド使用すると、SendMailErrorEventHandler代わりに派生クラスイベント処理することもできますChangePasswordCreateUserWizard から派生したクラスイベント処理する場合は、この手法が適してます。

イベント処理詳細については、「ASP.NET Web ページサーバー イベント処理」を参照してください

継承時の注意 派生クラスOnSendMailErrorオーバーライドする場合は、登録されているデリゲートイベント受け取ることができるように、基本クラスOnSendMailError メソッド呼び出してください

使用例使用例

ChangePassword Web コントロール使用し、SendMailError という名前の SendMailError イベントイベント ハンドラを含む ASP.NET ページ次のコード例示します。このコード例では、ASP.NET メンバシップフォーム認証使用するように構成されASP.NET Web サイトと、名前とパスワードわかっているユーザー作成されていることを前提にしています。詳細については、「方法 : 簡単なフォーム認証実装する」を参照してください

パスワード変更成功した場合SendingMail イベント ハンドラコードは、変更内容確認する電子メール メッセージユーザー送信します。このコード例実行するには、あらかじめサーバー上で SMTP構成しておく必要がありますSMTP サーバー構成する方法については、「方法 : IIS 内で SMTP 仮想サーバーインストールおよび構成する」を参照してください。この例の目的では、必ずしも SMTP サーバー構成する要はありません。この例は、電子メール メッセージの送信エラーテストするために構築されています。

メール サーバー正しく構成されていない場合、または他のエラー発生して電子メール メッセージ送信できない場合SendMailError 関数呼び出されます。ユーザーメッセージ表示されます。さらに、MySamplesSite という名前のイベント ソースが既に存在するという前提で、Windowsアプリケーション イベント ログイベント記録されます。指定されイベント ソース作成するには、下記コード例参照してくださいイベント ソース作成詳細については、「ASP.NET Web ページサーバー イベント処理」を参照してくださいエラー処理されたことを示すために、SendMailErrorEventArgs オブジェクトHandled プロパティtrue設定されます。

<%@ 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  >
<head runat="server">
  <title>ChangePassword including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div 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="C#" AutoEventWireup="True" %>

<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  >
<head runat="server">
  <title>ChangePassword including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div 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 という名前のイベント ソースプログラムによってアプリケーション ログ追加する必要がある場合は、次のコード例使用します最初コード例正常に動作させるには、このイベント ソース存在する必要があります次のコード例には、管理者特権が必要です。

Imports System
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
#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());
            }
        }
    }
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
    System.Web.UI.WebControls.SendMailErrorEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SendMailErrorEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

SendMailErrorEventArgs クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim e As Exception

Dim instance As New SendMailErrorEventArgs(e)
public SendMailErrorEventArgs (
    Exception e
)
public:
SendMailErrorEventArgs (
    Exception^ e
)
public SendMailErrorEventArgs (
    Exception e
)
public function SendMailErrorEventArgs (
    e : Exception
)

パラメータ

e

例外格納した Exception オブジェクト

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SendMailErrorEventArgs クラス
SendMailErrorEventArgs メンバ
System.Web.UI.WebControls 名前空間
CreateUserWizard.SendMailError イベント
ChangePassword.SendMailError イベント
PasswordRecovery.SendMailError イベント
MailMessage
その他の技術情報
ASP.NET Web ページサーバー イベント処理
イベントの処理と発生
Web サイト管理ツールの [アプリケーション] タブ
方法 : IIS 内で SMTP 仮想サーバーインストールおよび構成する

SendMailErrorEventArgs プロパティ


SendMailErrorEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SendMailErrorEventArgs クラス
System.Web.UI.WebControls 名前空間
CreateUserWizard.SendMailError イベント
ChangePassword.SendMailError イベント
PasswordRecovery.SendMailError イベント
MailMessage

その他の技術情報

ASP.NET Web ページサーバー イベント処理
イベントの処理と発生
Web サイト管理ツールの [アプリケーション] タブ
ログイン コントロールセキュリティ保護
Web アプリケーションセキュリティに関する基本的な対策

SendMailErrorEventArgs メンバ

ChangePassword、CreateUserWizard、PasswordRecovery など各コントロールSendMailError イベントデータ提供します

SendMailErrorEventArgs データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド SendMailErrorEventArgs SendMailErrorEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SendMailErrorEventArgs クラス
System.Web.UI.WebControls 名前空間
CreateUserWizard.SendMailError イベント
ChangePassword.SendMailError イベント
PasswordRecovery.SendMailError イベント
MailMessage

その他の技術情報

ASP.NET Web ページサーバー イベント処理
イベントの処理と発生
Web サイト管理ツールの [アプリケーション] タブ
ログイン コントロールセキュリティ保護
Web アプリケーションセキュリティに関する基本的な対策


このページでは「.NET Framework クラス ライブラリ リファレンス」からSendMailErrorEventArgsを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSendMailErrorEventArgsを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSendMailErrorEventArgs を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SendMailErrorEventArgs」の関連用語

SendMailErrorEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SendMailErrorEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS