MailMessage コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
MailMessage クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| MailMessage() |
MailMessage クラスの空のインスタンスを初期化します。 |
| MailMessage(MailAddress, MailAddress) |
指定したMailAddress クラス オブジェクトを使用して、MailMessage クラスの新しいインスタンスを初期化します。 |
| MailMessage(String, String) |
指定したString クラス オブジェクトを使用して、MailMessage クラスの新しいインスタンスを初期化します。 |
| MailMessage(String, String, String, String) |
MailMessage クラスの新しいインスタンスを初期化します。 |
MailMessage()
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
MailMessage クラスの空のインスタンスを初期化します。
public:
MailMessage();
public MailMessage();
Public Sub New ()
注釈
From が存在する場合は、mailSettings<smtp> 要素 (ネットワーク設定) のネットワーク要素の値に設定されます。
適用対象
MailMessage(MailAddress, MailAddress)
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
指定したMailAddress クラス オブジェクトを使用して、MailMessage クラスの新しいインスタンスを初期化します。
public:
MailMessage(System::Net::Mail::MailAddress ^ from, System::Net::Mail::MailAddress ^ to);
public MailMessage(System.Net.Mail.MailAddress from, System.Net.Mail.MailAddress to);
new System.Net.Mail.MailMessage : System.Net.Mail.MailAddress * System.Net.Mail.MailAddress -> System.Net.Mail.MailMessage
Public Sub New (from As MailAddress, to As MailAddress)
パラメーター
- from
- MailAddress
電子メール メッセージの送信者のアドレスを含む MailAddress 。
- to
- MailAddress
電子メール メッセージの受信者のアドレスを含む MailAddress 。
例外
from または to の形式が正しくありません。
例
次のコード例は、このコンストラクターの呼び出しを示しています。
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);
}
Public Shared Sub CreateTestMessage3()
Dim [to] As MailAddress = New MailAddress("jane@contoso.com")
Dim from As MailAddress = New MailAddress("ben@contoso.com")
Dim message As MailMessage = 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.
Dim client As SmtpClient = 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)
End Sub
注釈
From プロパティはfromを使用して初期化され、To プロパティは to を使用して初期化されます。
適用対象
MailMessage(String, String)
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
指定したString クラス オブジェクトを使用して、MailMessage クラスの新しいインスタンスを初期化します。
public:
MailMessage(System::String ^ from, System::String ^ to);
public MailMessage(string from, string to);
new System.Net.Mail.MailMessage : string * string -> System.Net.Mail.MailMessage
Public Sub New (from As String, to As String)
パラメーター
例外
from または to の形式が正しくありません。
例
次のコード例は、このコンストラクターの呼び出しを示しています。
public static void CreateTestMessage2(string server)
{
string to = "jane@contoso.com";
string from = "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.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send email on the client's behalf.
client.UseDefaultCredentials = true;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
ex.ToString());
}
}
Public Shared Sub CreateTestMessage2(ByVal server As String)
Dim [to] As String = "jane@contoso.com"
Dim from As String = "ben@contoso.com"
Dim message As MailMessage = 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."
Dim client As SmtpClient = New SmtpClient(server)
' Credentials are necessary if the server requires the client
' to authenticate before it will send email on the client's behalf.
client.UseDefaultCredentials = True
Try
client.Send(message)
Catch ex As Exception
Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString())
End Try
End Sub
注釈
From プロパティはfromを使用して初期化され、To プロパティは to を使用して初期化されます。
適用対象
MailMessage(String, String, String, String)
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
- ソース:
- MailMessage.cs
MailMessage クラスの新しいインスタンスを初期化します。
public:
MailMessage(System::String ^ from, System::String ^ to, System::String ^ subject, System::String ^ body);
public MailMessage(string from, string to, string? subject, string? body);
public MailMessage(string from, string to, string subject, string body);
new System.Net.Mail.MailMessage : string * string * string * string -> System.Net.Mail.MailMessage
Public Sub New (from As String, to As String, subject As String, body As String)
パラメーター
例外
from または to の形式が正しくありません。
例
次のコード例は、このコンストラクターの呼び出しを示しています。
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);
}
Public Shared Sub CreateTimeoutTestMessage(ByVal server As String)
Dim [to] As String = "jane@contoso.com"
Dim from As String = "ben@contoso.com"
Dim subject As String = "Using the new SMTP client."
Dim body As String = "Using this new feature, you can send an email message from an application very easily."
Dim message As MailMessage = New MailMessage(from, [to], subject, body)
Dim client As SmtpClient = 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)
End Sub
注釈
新しい MailMessage オブジェクトのプロパティは、次のように初期化されます。
| パラメーター | 財産 |
|---|---|
from |
From |
to |
To |
subject |
Subject |
body |
Body |
既定では、サブジェクトとコンテンツは、ローカル コンピューターの設定に基づいて既定のエンコードを使用するものと見なされます。 BodyEncodingプロパティとSubjectEncodingプロパティを使用して、さまざまなエンコーディングを指定します。