更新 : 2007 年 11 月
同期的な Send 呼び出しがタイムアウトになるまでの時間を指定する値を取得または設定します。
名前空間 :
System.Net.Mail アセンブリ :
System (System.dll 内)
Public Property Timeout As Integer
Dim instance As SmtpClient
Dim value As Integer
value = instance.Timeout
instance.Timeout = value
public int Timeout { get; set; }
public:
property int Timeout {
int get ();
void set (int value);
}
/** @property */
public int get_Timeout()
/** @property */
public void set_Timeout(int value)
public function get Timeout () : int
public function set Timeout (value : int)
既定では、Send メソッドを呼び出すと、その操作が完了するまでブロックされます。Timeout プロパティが正の値に設定されていて Send 操作が指定の時間内に完了できなかった場合は、SmtpClient クラスによって SmtpException 例外がスローされます。
メッセージを送信し、同時にアプリケーション スレッドで実行を継続するには、SendAsync メソッドを使用します。
タイムアウト値の取得と設定を行うコード例を次に示します。
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 e-mail 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 e-mail on the client's behalf.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
}
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 e-mail 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 e-mail 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 e-mail 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.",
System.Convert.ToString(client.get_Timeout()));
client.set_Timeout(100);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.set_Credentials(CredentialCache.get_DefaultNetworkCredentials());
client.Send(message);
} //CreateTimeoutTestMessage
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0
参照