SmtpException 클래스

정의

SmtpClient에서 Send 또는 SendAsync 작업을 완료할 수 없을 때 throw되는 예외를 나타냅니다.

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
파생
특성
구현

예제

다음 코드 예제에서는 예외가 throw 될 때 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)

SmtpExceptionSerializationInfo 클래스에 지정된 인스턴스에서 StreamingContext 클래스의 새 인스턴스를 초기화합니다.

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

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo을 serialize하는 데 필요한 데이터로 SmtpException 인스턴스를 채웁니다.

GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 예외에 대한 문자열 표현을 만들고 반환합니다.

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않습니다.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

명시적 인터페이스 구현

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo을 serialize하는 데 필요한 데이터로 SmtpException 인스턴스를 채웁니다.

적용 대상