MailAddress コンストラクター
定義
MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class.
オーバーロード
MailAddress(String) |
指定したアドレスを使用して、MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class using the specified address. |
MailAddress(String, String) |
アドレスと表示名を指定して、MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class using the specified address and display name. |
MailAddress(String, String, Encoding) |
アドレス、表示名、およびエンコーディングを指定して、MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class using the specified address, display name, and encoding. |
MailAddress(String)
指定したアドレスを使用して、MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class using the specified address.
public:
MailAddress(System::String ^ address);
public MailAddress (string address);
new System.Net.Mail.MailAddress : string -> System.Net.Mail.MailAddress
Public Sub New (address As String)
パラメーター
例外
address
が null
です。address
is null
.
address
が、認識される形式ではありません。address
is not in a recognized format.
例
次のコード例では、このコンストラクターを使用して MailAddress 、 Bcc 電子メールメッセージの受信者のオブジェクトを作成します。The following code example uses this constructor to create a MailAddress object for the Bcc recipient of an email message.
static void CreateBccTestMessage( String^ server )
{
MailAddress^ from = gcnew MailAddress( L"ben@contoso.com",L"Ben Miller" );
MailAddress^ to = gcnew MailAddress( L"jane@contoso.com",L"Jane Clayton" );
MailMessage^ message = gcnew MailMessage( from,to );
message->Subject = L"Using the SmtpClient class.";
message->Body = L"Using this feature, you can send an email message from an application very easily.";
MailAddress^ bcc = gcnew MailAddress( L"manager1@contoso.com" );
message->Bcc->Add( bcc );
SmtpClient^ client = gcnew SmtpClient( server );
client->Credentials = CredentialCache::DefaultNetworkCredentials;
Console::WriteLine( L"Sending an email message to {0} and {1}.", to->DisplayName, message->Bcc );
try
{
client->Send( message );
}
catch ( Exception^ ex )
{
Console::WriteLine(L"Exception caught in CreateBccTestMessage(): {0}",
ex->ToString() );
}
client->~SmtpClient();
}
public static void CreateBccTestMessage(string server)
{
MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an email message from an application very easily.";
MailAddress bcc = new MailAddress("manager1@contoso.com");
message.Bcc.Add(bcc);
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an email message to {0} and {1}.",
to.DisplayName, message.Bcc.ToString());
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
ex.ToString());
}
}
注釈
パラメーターには、 address
山かっこでアドレスを囲む場合、表示名と関連付けられた電子メールアドレスを含めることができます。The address
parameter can contain a display name and the associated email address if you enclose the address in angle brackets. 次に例を示します。For example:
"Tom Smith <tsmith@contoso.com>"
表示名と山かっこの間には空白文字を使用できます。White space is permitted between the display name and the angle brackets.
次の表は、 MailAddress 前の例のアドレスを使用して構築されたオブジェクトのプロパティ値を示しています。The following table shows the property values for a MailAddress object constructed using the preceding example address.
プロパティProperty | [値]Value |
---|---|
DisplayName | "Tom Smith" |
Host | "contoso.com" |
User | "tsmith" |
Address | "tsmith@contoso.com" |
適用対象
MailAddress(String, String)
アドレスと表示名を指定して、MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class using the specified address and display name.
public:
MailAddress(System::String ^ address, System::String ^ displayName);
public MailAddress (string address, string? displayName);
public MailAddress (string address, string displayName);
new System.Net.Mail.MailAddress : string * string -> System.Net.Mail.MailAddress
Public Sub New (address As String, displayName As String)
パラメーター
- displayName
- String
address
に関連付けられた表示名を含む String。A String that contains the display name associated with address
. このパラメーターは、null
に設定できます。This parameter can be null
.
例外
address
が null
です。address
is null
.
address
が、認識される形式ではありません。address
is not in a recognized format.
- または --or-
address
に非 ASCII 文字が格納されています。address
contains non-ASCII characters.
例
次のコード例では、このコンストラクターを使用して MailAddress 、電子メールメッセージの送信者と受信者のインスタンスを作成します。The following code example uses this constructor to create MailAddress instances for the sender and recipient of an email message.
static void CreateBccTestMessage( String^ server )
{
MailAddress^ from = gcnew MailAddress( L"ben@contoso.com",L"Ben Miller" );
MailAddress^ to = gcnew MailAddress( L"jane@contoso.com",L"Jane Clayton" );
MailMessage^ message = gcnew MailMessage( from,to );
message->Subject = L"Using the SmtpClient class.";
message->Body = L"Using this feature, you can send an email message from an application very easily.";
MailAddress^ bcc = gcnew MailAddress( L"manager1@contoso.com" );
message->Bcc->Add( bcc );
SmtpClient^ client = gcnew SmtpClient( server );
client->Credentials = CredentialCache::DefaultNetworkCredentials;
Console::WriteLine( L"Sending an email message to {0} and {1}.", to->DisplayName, message->Bcc );
try
{
client->Send( message );
}
catch ( Exception^ ex )
{
Console::WriteLine(L"Exception caught in CreateBccTestMessage(): {0}",
ex->ToString() );
}
client->~SmtpClient();
}
public static void CreateBccTestMessage(string server)
{
MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an email message from an application very easily.";
MailAddress bcc = new MailAddress("manager1@contoso.com");
message.Bcc.Add(bcc);
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an email message to {0} and {1}.",
to.DisplayName, message.Bcc.ToString());
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
ex.ToString());
}
}
注釈
表示名の先頭と末尾の空白は保持されます。Leading and trailing white space in the display name is preserved.
に displayName
ASCII 以外の文字が含まれている場合、エンコードには iso-8859-1 文字セットが使用され displayName
ます。If displayName
contains non-ASCII characters, the iso-8859-1 character set is used for the displayName
encoding. ASCII 以外の文字のエンコードについては、RFC 1522 で説明されています。これは、で入手でき https://www.ietf.org/ ます。Encoding non-ASCII characters is discussed in RFC 1522, which is available at https://www.ietf.org/.
に address
表示名が含まれ、 displayName
がではなく、が null
と等しくない場合 String.Empty 、は displayName
で指定された値をオーバーライドし address
ます。If address
contains a display name, and displayName
is not null
and is not equal to String.Empty, displayName
overrides the value specified in address
.
適用対象
MailAddress(String, String, Encoding)
アドレス、表示名、およびエンコーディングを指定して、MailAddress クラスの新しいインスタンスを初期化します。Initializes a new instance of the MailAddress class using the specified address, display name, and encoding.
public:
MailAddress(System::String ^ address, System::String ^ displayName, System::Text::Encoding ^ displayNameEncoding);
public MailAddress (string address, string? displayName, System.Text.Encoding? displayNameEncoding);
public MailAddress (string address, string displayName, System.Text.Encoding displayNameEncoding);
new System.Net.Mail.MailAddress : string * string * System.Text.Encoding -> System.Net.Mail.MailAddress
Public Sub New (address As String, displayName As String, displayNameEncoding As Encoding)
パラメーター
- displayName
- String
address
に関連付けられた表示名を格納している String。A String that contains the display name associated with address
.
- displayNameEncoding
- Encoding
displayName
で使用される文字セットを定義する Encoding。The Encoding that defines the character set used for displayName
.
例外
address
が null
です。address
is null
.
- または --or-
displayName
が null
です。displayName
is null
.
address
が Empty ("") です。address
is Empty ("").
- または --or-
displayName
が Empty ("") です。displayName
is Empty ("").
address
が、認識される形式ではありません。address
is not in a recognized format.
- または --or-
address
に非 ASCII 文字が含まれています。address
contains non-ASCII characters.
例
次のコード例では、このコンストラクターを使用して MailAddress 、電子メールメッセージの送信者のインスタンスを作成します。The following code example uses this constructor to create MailAddress instances for the sender of an email message.
// Create a mailing address that includes a UTF8
// character in the display name.
MailAddress^ from = gcnew MailAddress("jane@contoso.com",
"Jane " + (wchar_t)0xD8 + " Clayton",
System::Text::Encoding::UTF8);
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("jane@contoso.com",
"Jane " + (char)0xD8+ " Clayton",
System.Text.Encoding.UTF8);
' Create a mailing address that includes a UTF8 character
' in the display name.
Dim mailFrom As New MailAddress("jane@contoso.com", "Jane " & ChrW(&HD8) & " Clayton", System.Text.Encoding.UTF8)
注釈
表示名の先頭と末尾の空白は保持されます。Leading and trailing white space in the display name is preserved.
に address
表示名が含まれ、 displayName
がではなく、が null
と等しくない場合 String.Empty 、は displayName
で指定された値をオーバーライドし address
ます。If address
contains a display name, and displayName
is not null
and is not equal to String.Empty, displayName
overrides the value specified in address
.
MailAddressメソッドは、パラメーターが有効かどうかを確認しません displayName
。The MailAddress method does not check if the displayName
parameter is valid. このメソッドは、プロパティによって表示されない周囲の引用符を削除 DisplayName します。This method removes surrounding quotes not displayed by the DisplayName property. ASCIIパラメーターでまたはが指定されている場合を除き、転送の前に引用符が追加され Unicode displayNameEncoding
ます。Quotes will be added before transmission, except where ASCII or Unicode is specified in the displayNameEncoding
parameter. パラメーターで指定されたエンコーディングは、 displayNameEncoding
DisplayName 転送前にプロパティに適用されるか、 ASCII Unicode パラメーターで指定され displayNameEncoding
ます。The encoding specified in the displayNameEncoding
parameter will be applied to the DisplayName property before transmission ASCII or Unicode is specified in the displayNameEncoding
parameter. UTF8 none が指定されている場合、は既定のエンコーディングです。UTF8 is the default encoding if none is specified.
サポートされているメールアドレスの形式の詳細については、「」を参照してください MailAddress 。For more information on supported mail address formats, see MailAddress.