SmtpClient.Timeout SmtpClient.Timeout SmtpClient.Timeout SmtpClient.Timeout Property

定義

同期的な Send 呼び出しがタイムアウトになるまでの時間を指定する値を取得または設定します。Gets or sets a value that specifies the amount of time after which a synchronous Send call times out.

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

プロパティ値

タイムアウト値 (ミリ秒) を指定する Int32An Int32 that specifies the time-out value in milliseconds. 既定値は 100,000 ミリ秒 (100 秒) です。The default value is 100,000 (100 seconds).

例外

設定操作として指定した値が 0 未満です。The value specified for a set operation was less than zero.

電子メールが送信中の場合、このプロパティの値は変更できません。You cannot change the value of this property when an email is being sent.

次のコード例では、取得とタイムアウト値の設定を示します。The following code example demonstrates getting and setting the time-out value.

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操作が完了するまでブロックするメソッド。By default, calls to the Send method block until the operation completes. 設定した場合、Timeoutプロパティを正の値とSend、割り当てられた時間で操作を完了できません、SmtpClientクラスがスローされます、SmtpException例外。If you set the Timeout property to a positive value, and a Send operation cannot complete in the allotted time, the SmtpClient class throws an SmtpException exception.

メッセージを送信し、アプリケーションのスレッドで実行を継続して、使用、SendAsyncメソッド。To send a message and continue executing in the application thread, use the SendAsync method.

適用対象