다음을 통해 공유


MailMessage.To 속성

정의

이 전자 메일 메시지의 받는 사람이 포함된 주소 컬렉션을 가져옵니다.

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 .

예제

다음 코드 예제에서는 속성을 설정 하는 방법을 보여 줍니다 To .

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());
    }
}
Public Shared Sub CreateTestMessage4(ByVal server As String)
    Dim from As MailAddress = New MailAddress("ben@contoso.com")
    Dim [to] As MailAddress = New MailAddress("Jane@contoso.com")
    Dim message As MailMessage = 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."
    Dim client As SmtpClient = 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 ex As Exception
        Console.WriteLine("Exception caught in CreateTestMessage4(): {0}", ex.ToString())
    End Try
End Sub

설명

To 속성은 전자 메일 메시지의 To 줄에서 주소를 지정하는 데 사용됩니다. 전자 메일 메시지에 받는 사람을 추가하려면 받는 사람의 주소를 만든 MailAddress 다음 이 속성에서 반환된 컬렉션에 해당 개체를 추가합니다.

적용 대상