SmtpClient.Timeout 속성

정의

동기 Send 호출이 완료되어야 하는 제한 시간을 지정하는 값을 가져오거나 설정합니다.

public:
 property int Timeout { int get(); void set(int value); };
public int Timeout { get; set; }
member this.Timeout : int with get, set
Public Property Timeout As Integer

속성 값

제한 시간 값(밀리초)을 지정하는 Int32입니다. 기본값은 100,000(100초)입니다.

예외

set 작업에 지정된 값이 0보다 작은 경우

전자 메일을 보내는 동안 이 속성 값을 변경할 수 없습니다.

예제

다음 코드 예제에서는 제한 시간 값을 가져오고 설정하는 방법을 보여 줍니다.

static void CreateTimeoutTestMessage( String^ server )
{
   String^ to = L"jane@contoso.com";
   String^ from = L"ben@contoso.com";
   String^ subject = L"Using the new SMTP client.";
   String^ body = L"Using this new feature, you can send an email message from an application very easily.";
   MailMessage^ message = gcnew MailMessage( from,to,subject,body );
   SmtpClient^ client = gcnew SmtpClient( server );
   Console::WriteLine( L"Changing time out from {0} to 100.", client->Timeout );
   client->Timeout = 100;
   
   // Credentials are necessary if the server requires the client 
   // to authenticate before it will send email on the client's behalf.
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );
}
public static void CreateTimeoutTestMessage(string server)
{
    string to = "jane@contoso.com";
    string from = "ben@contoso.com";
    string subject = "Using the new SMTP client.";
    string body = @"Using this new feature, you can send an email message from an application very easily.";
    MailMessage message = new MailMessage(from, to, subject, body);
    SmtpClient client = new SmtpClient(server);
    Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
    client.Timeout = 100;
    // Credentials are necessary if the server requires the client
    // to authenticate before it will send email on the client's behalf.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    client.Send(message);
}

설명

기본적으로 는 작업이 완료될 때까지 메서드 블록을 호출 Send 합니다. 속성을 양수 값으로 설정하고 Timeout 할당된 시간에 작업을 완료할 수 없는 경우 클래스는 SmtpClient 예외를 SmtpException throw Send 합니다.

메시지를 보내고 애플리케이션 스레드에서 실행을 계속 사용 하 여를 SendAsync 메서드.

적용 대상