SmtpClient コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
SmtpClient クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| SmtpClient() |
構成ファイルの設定を使用して、 SmtpClient クラスの新しいインスタンスを初期化します。 |
| SmtpClient(String) |
指定した SMTP サーバーを使用して電子メールを送信する SmtpClient クラスの新しいインスタンスを初期化します。 |
| SmtpClient(String, Int32) |
指定した SMTP サーバーとポートを使用して電子メールを送信する SmtpClient クラスの新しいインスタンスを初期化します。 |
SmtpClient()
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
構成ファイルの設定を使用して、 SmtpClient クラスの新しいインスタンスを初期化します。
public:
SmtpClient();
public SmtpClient();
Public Sub New ()
例
次のコード例は、電子メール メッセージの送信を示しています。
public static void CreateTestMessage3()
{
MailAddress to = new MailAddress("jane@contoso.com");
MailAddress from = new MailAddress("ben@contoso.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an email message from an application very easily.";
// Use the application or machine configuration to get the
// host, port, and credentials.
SmtpClient client = new SmtpClient();
Console.WriteLine("Sending an email message to {0} at {1} by using the SMTP host={2}.",
to.User, to.Host, client.Host);
client.Send(message);
}
アプリケーションまたはコンピューター構成ファイルの <mailSettings> ノードの例については、「 <mailSettings> 要素 (ネットワーク設定)」を参照してください。
注釈
このコンストラクターは、アプリケーションまたはコンピューター構成ファイルの設定を使用して、新しいSmtpClientのHost、Credentials、およびPortプロパティを初期化します。 詳細については、「 <mailSettings> 要素 (ネットワーク設定)」を参照してください。
適用対象
SmtpClient(String)
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
指定した SMTP サーバーを使用して電子メールを送信する SmtpClient クラスの新しいインスタンスを初期化します。
public:
SmtpClient(System::String ^ host);
public SmtpClient(string? host);
public SmtpClient(string host);
new System.Net.Mail.SmtpClient : string -> System.Net.Mail.SmtpClient
Public Sub New (host As String)
パラメーター
例
次のコード例は、このコンストラクターの呼び出しを示しています。
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);
}
注釈
host パラメーターは、Host プロパティの値を初期化するために使用されます。
CredentialsプロパティとPortプロパティは、アプリケーションまたはコンピューター構成ファイルの設定を使用して初期化されます。
hostがnullまたはString.Emptyと等しい場合、Hostはアプリケーションまたはマシン構成ファイルの設定を使用して初期化されます。
アプリケーション構成ファイルとコンピューター構成ファイルの使用方法の詳細については、「 <mailSettings> 要素 (ネットワーク設定)」を参照してください。 SmtpClientコンストラクターまたはプロパティを使用して情報が指定されている場合、この情報は構成ファイルの設定をオーバーライドします。
適用対象
SmtpClient(String, Int32)
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
- ソース:
- SmtpClient.cs
指定した SMTP サーバーとポートを使用して電子メールを送信する SmtpClient クラスの新しいインスタンスを初期化します。
public:
SmtpClient(System::String ^ host, int port);
public SmtpClient(string? host, int port);
public SmtpClient(string host, int port);
new System.Net.Mail.SmtpClient : string * int -> System.Net.Mail.SmtpClient
Public Sub New (host As String, port As Integer)
パラメーター
例外
port は 0 未満には設定できません。
例
次のコード例は、このコンストラクターの呼び出しを示しています。
public static void CreateTestMessage1(string server, int port)
{
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, port);
// 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);
}
注釈
hostパラメーターとport パラメーターは、それぞれHostプロパティとPortプロパティの値を設定します。
hostがnullまたはString.Emptyと等しい場合、Hostはアプリケーションまたはマシン構成ファイルの設定を使用して初期化されます。
portが 0 の場合、Portはアプリケーションまたはコンピューター構成ファイルの設定を使用して初期化されます。
Credentials プロパティは、アプリケーションまたはコンピューター構成ファイルの設定を使用して初期化されます。
アプリケーション構成ファイルとコンピューター構成ファイルの使用方法の詳細については、「 <mailSettings> 要素 (ネットワーク設定)」を参照してください。 SmtpClientコンストラクターまたはプロパティを使用して情報が指定されている場合、この情報は構成ファイルの設定をオーバーライドします。