SmtpException クラス

定義

SmtpClientSend 操作または SendAsync 操作を完了できない場合にスローされる例外を表します。

public ref class SmtpException : Exception
public class SmtpException : Exception
[System.Serializable]
public class SmtpException : Exception
type SmtpException = class
    inherit Exception
    interface ISerializable
[<System.Serializable>]
type SmtpException = class
    inherit Exception
    interface ISerializable
Public Class SmtpException
Inherits Exception
継承
SmtpException
派生
属性
実装

次のコード例では、例外がスローされたときにエラー メッセージを SmtpException 表示します。

static void RetryIfBusy( String^ server )
{
   MailAddress^ from = gcnew MailAddress( L"ben@contoso.com" );
   MailAddress^ to = gcnew MailAddress( L"jane@contoso.com" );
   MailMessage^ message = gcnew MailMessage( from,to );
   
   // message.Subject = "Using the SmtpClient class.";
   message->Subject = L"Using the SmtpClient class.";
   message->Body = L"Using this feature, you can send an email message from an application very easily.";
   
   // Add a carbon copy recipient.
   MailAddress^ copy = gcnew MailAddress( L"Notifications@contoso.com" );
   message->CC->Add( copy );
   SmtpClient^ client = gcnew SmtpClient( server );
   
   // Include credentials if the server requires them.
   client->Credentials = dynamic_cast<ICredentialsByHost^>(CredentialCache::DefaultNetworkCredentials);
   Console::WriteLine( L"Sending an email message to {0} using the SMTP host {1}.", to->Address, client->Host );
   try
   {
      client->Send( message );
   }
   catch ( SmtpFailedRecipientsException^ ex ) 
   {
      for ( int i = 0; i < ex->InnerExceptions->Length; i++ )
      {
         SmtpStatusCode status = ex->InnerExceptions[ i ]->StatusCode;
         if ( status == SmtpStatusCode::MailboxBusy || status == SmtpStatusCode::MailboxUnavailable )
         {
            Console::WriteLine( L"Delivery failed - retrying in 5 seconds." );
            System::Threading::Thread::Sleep( 5000 );
            client->Send( message );
         }
         else
         {
            Console::WriteLine( L"Failed to deliver message to {0}", ex->InnerExceptions[ i ] );
         }

      }
   }
   catch ( Exception^ ex )
   {
       Console::WriteLine(L"Exception caught in RetryIfBusy(): {0}", 
                     ex->ToString() );
   }
   finally
   {
      client->~SmtpClient();
   }
}
public static void RetryIfBusy(string server)
{
    MailAddress from = new MailAddress("ben@contoso.com");
    MailAddress to = new MailAddress("jane@contoso.com");
    MailMessage message = new MailMessage(from, to);
    // message.Subject = "Using the SmtpClient class.";
    message.Subject = "Using the SmtpClient class.";
    message.Body = @"Using this feature, you can send an email message from an application very easily.";
    // Add a carbon copy recipient.
    MailAddress copy = new MailAddress("Notifications@contoso.com");
    message.CC.Add(copy);
    SmtpClient client = new SmtpClient(server);
    // Include credentials if the server requires them.
    client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
    Console.WriteLine("Sending an email message to {0} using the SMTP host {1}.",
         to.Address, client.Host);
    try
    {
        client.Send(message);
    }
    catch (SmtpFailedRecipientsException ex)
    {
        for (int i = 0; i < ex.InnerExceptions.Length; i++)
        {
            SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
            if (status == SmtpStatusCode.MailboxBusy ||
                status == SmtpStatusCode.MailboxUnavailable)
            {
                Console.WriteLine("Delivery failed - retrying in 5 seconds.");
                System.Threading.Thread.Sleep(5000);
                client.Send(message);
            }
            else
            {
                Console.WriteLine("Failed to deliver message to {0}",
                    ex.InnerExceptions[i].FailedRecipient);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in RetryIfBusy(): {0}",
                ex.ToString());
    }
}

注釈

プロパティには StatusCode 、SMTP サーバーによって返される状態コードが含まれています。

コンストラクター

SmtpException()

SmtpException クラスの新しいインスタンスを初期化します。

SmtpException(SerializationInfo, StreamingContext)

SerializationInfo クラスと StreamingContext クラスの指定したインスタンスから、SmtpException クラスの新しいインスタンスを初期化します。

SmtpException(SmtpStatusCode)

ステータス コードを指定して、SmtpException クラスの新しいインスタンスを初期化します。

SmtpException(SmtpStatusCode, String)

指定したステータス コードとエラー メッセージを使用して、SmtpException クラスの新しいインスタンスを初期化します。

SmtpException(String)

指定されたエラー メッセージで SmtpException クラスの新しいインスタンスを初期化します。

SmtpException(String, Exception)

指定したエラー メッセージと内部例外を使用して、SmtpException クラスの新しいインスタンスを初期化します。

プロパティ

Data

例外に関する追加のユーザー定義情報を提供する、キーと値のペアのコレクションを取得します。

(継承元 Exception)
HelpLink

この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。

(継承元 Exception)
HResult

特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。

(継承元 Exception)
InnerException

現在の例外の原因となる Exception インスタンスを取得します。

(継承元 Exception)
Message

現在の例外を説明するメッセージを取得します。

(継承元 Exception)
Source

エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。

(継承元 Exception)
StackTrace

呼び出し履歴で直前のフレームの文字列形式を取得します。

(継承元 Exception)
StatusCode

電子メール メッセージが送信されたときに SMTP サーバーによって返されるステータス コードを取得します。

TargetSite

現在の例外がスローされたメソッドを取得します。

(継承元 Exception)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetBaseException()

派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の根本原因である Exception を返します。

(継承元 Exception)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo インスタンスに、SmtpException をシリアル化するために必要なデータを設定します。

GetType()

現在のインスタンスのランタイム型を取得します。

(継承元 Exception)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在の例外の文字列形式を作成して返します。

(継承元 Exception)

イベント

SerializeObjectState
古い.

例外がシリアル化され、例外に関するシリアル化されたデータを含む例外状態オブジェクトが作成されたときに発生します。

(継承元 Exception)

明示的なインターフェイスの実装

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo インスタンスに、SmtpException をシリアル化するために必要なデータを設定します。

適用対象