SmtpClient 생성자

정의

SmtpClient 클래스의 새 인스턴스를 초기화합니다.

오버로드

SmtpClient()

구성 파일 설정을 사용하여 SmtpClient 클래스의 새 인스턴스를 초기화합니다.

SmtpClient(String)

지정된 SMTP 서버를 사용하여 이메일을 보내는 SmtpClient 클래스의 새 인스턴스를 초기화합니다.

SmtpClient(String, Int32)

지정된 SMTP 서버 및 포트를 사용하여 이메일을 보내는 SmtpClient 클래스의 새 인스턴스를 초기화합니다.

SmtpClient()

Source:
SmtpClient.cs
Source:
SmtpClient.cs
Source:
SmtpClient.cs

구성 파일 설정을 사용하여 SmtpClient 클래스의 새 인스턴스를 초기화합니다.

public:
 SmtpClient();
public SmtpClient ();
Public Sub New ()

예제

다음 코드 예제에서는 전자 메일 메시지를 보내는 방법을 보여 줍니다.

static void CreateTestMessage3()
{
   MailAddress^ to = gcnew MailAddress( L"jane@contoso.com" );
   MailAddress^ from = gcnew MailAddress( L"ben@contoso.com" );
   MailMessage^ message = gcnew MailMessage( from,to );
   message->Subject = L"Using the new SMTP client.";
   message->Body = L"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 = gcnew SmtpClient;
   Console::WriteLine( L"Sending an email message to {0} at {1} by using the SMTP host {2}.", to->User, to->Host, client->Host );
   client->Send( message );
}
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> 요소(네트워크 설정)를 참조<하세요.

설명

이 생성자는 Host, Credentials, 및 Port 새 속성 SmtpClient 애플리케이션 또는 컴퓨터 구성 파일의 설정을 사용 하 여 합니다. 자세한 내용은 mailSettings> 요소(네트워크 설정)를 참조<하세요.

적용 대상

SmtpClient(String)

Source:
SmtpClient.cs
Source:
SmtpClient.cs
Source:
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)

매개 변수

host
String

SMTP 트랜잭션에 사용되는 호스트 컴퓨터의 이름 또는 IP 주소가 들어 있는 String입니다.

예제

다음 코드 예제에서는이 생성자를 호출 하는 방법을 보여 줍니다.

static void CreateTimeoutTestMessage( String^ server )
{
   String^ to = L"jane@contoso.com";
   String^ from = L"ben@contoso.com";
   String^ subject = L"Using the new SMTP client.";
   String^ body = L"Using this new feature, you can send an email message from an application very easily.";
   MailMessage^ message = gcnew MailMessage( from,to,subject,body );
   SmtpClient^ client = gcnew SmtpClient( server );
   Console::WriteLine( L"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 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 초기화하는 데 사용됩니다. 합니다 CredentialsPort 속성이 애플리케이션 또는 컴퓨터 구성 파일의 설정을 사용 하 여 초기화 됩니다. 하는 경우 host 됩니다 null 크거나 String.Empty, Host 애플리케이션 또는 컴퓨터 구성 파일의 설정을 사용 하 여 초기화 됩니다.

애플리케이션 및 컴퓨터 구성 파일 사용에 대한 자세한 내용은 mailSettings> 요소(네트워크 설정)를 참조<하세요. 생성자 또는 속성을 사용하여 SmtpClient 정보를 지정하는 경우 이 정보는 구성 파일 설정을 재정의합니다.

적용 대상

SmtpClient(String, Int32)

Source:
SmtpClient.cs
Source:
SmtpClient.cs
Source:
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)

매개 변수

host
String

SMTP 트랜잭션에 사용되는 호스트의 이름 또는 IP 주소가 들어 있는 String입니다.

port
Int32

host에 사용되는 포트가 들어 있는 0보다 큰 Int32입니다.

예외

port가 0보다 작은 경우

예제

다음 코드 예제에서는이 생성자를 호출 하는 방법을 보여 줍니다.

static void CreateTestMessage1( String^ server, int port )
{
   String^ to = L"jane@contoso.com";
   String^ from = L"ben@contoso.com";
   String^ subject = L"Using the new SMTP client.";
   String^ body = L"Using this new feature, you can send an email message from an application very easily.";
   MailMessage^ message = gcnew MailMessage( from,to,subject,body );
   SmtpClient^ client = gcnew 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 );
   client->~SmtpClient();
}
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);
}

설명

port 매개 변수는 host 각각 및 Port 속성의 Host 값을 설정합니다. 하는 경우 host 됩니다 null 크거나 String.Empty, Host 애플리케이션 또는 컴퓨터 구성 파일의 설정을 사용 하 여 초기화 됩니다. 하는 경우 port 가 0 이면 Port 애플리케이션 또는 컴퓨터 구성 파일의 설정을 사용 하 여 초기화 됩니다. Credentials 속성은 애플리케이션 또는 컴퓨터 구성 파일의 설정을 사용 하 여 초기화 됩니다.

애플리케이션 및 컴퓨터 구성 파일 사용에 대한 자세한 내용은 mailSettings> 요소(네트워크 설정)를 참조<하세요. 생성자 또는 속성을 사용하여 SmtpClient 정보를 지정하는 경우 이 정보는 구성 파일 설정을 재정의합니다.

적용 대상