MailMessage.To プロパティ

定義

この電子メール メッセージの受信者を格納するアドレスのコレクションを取得します。Gets the address collection that contains the recipients of this email message.

public:
 property System::Net::Mail::MailAddressCollection ^ To { System::Net::Mail::MailAddressCollection ^ get(); };
public System.Net.Mail.MailAddressCollection To { get; }
member this.To : System.Net.Mail.MailAddressCollection
Public ReadOnly Property To As MailAddressCollection

プロパティ値

書き込み可能な MailAddressCollection オブジェクト。A writable MailAddressCollection object.

次のコード例は、To プロパティを設定する方法を示しています。The following code example demonstrates setting the To property.

static void CreateTestMessage4( String^ server )
{
   MailAddress^ from = gcnew MailAddress( L"ben@contoso.com" );
   MailAddress^ to = gcnew MailAddress( L"Jane@contoso.com" );
   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.";
   SmtpClient^ client = gcnew SmtpClient( server );
   Console::WriteLine( L"Sending an email message to {0} by using SMTP host {1} port {2}.", to, client->Host, client->Port );
   client->Send( message );
   client->~SmtpClient();
}


public static void CreateTestMessage4(string server)
{
    MailAddress from = new MailAddress("ben@contoso.com");
    MailAddress to = new MailAddress("Jane@contoso.com");
    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.";
    SmtpClient client = new SmtpClient(server);
    Console.WriteLine("Sending an email message to {0} by using SMTP host {1} port {2}.",
         to.ToString(), client.Host, client.Port);

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateTestMessage4(): {0}", 
            ex.ToString());
  }
}

注釈

To プロパティは、電子メールメッセージの 宛先行のアドレスを指定するために使用されます。The To property is used to designate the addresses on the To line of an email message. 電子メールメッセージに受信者を追加するには、受信者のアドレスの MailAddress を作成し、このプロパティによって返されるコレクションにそのオブジェクトを追加します。To add a recipient to an email message, create a MailAddress for the recipient's address, and then add that object to the collection returned by this property.

適用対象