SmtpClient.Host Propriedade

Definição

Obtém ou define o nome ou endereço IP do host usado para transações de SMTP.Gets or sets the name or IP address of the host used for SMTP transactions.

public:
 property System::String ^ Host { System::String ^ get(); void set(System::String ^ value); };
public string? Host { get; set; }
public string Host { get; set; }
member this.Host : string with get, set
Public Property Host As String

Valor da propriedade

String

Um String que contém o nome ou endereço IP do computador usado para transações de SMTP.A String that contains the name or IP address of the computer to use for SMTP transactions.

Exceções

O valor especificado para uma operação de definição é null.The value specified for a set operation is null.

O valor especificado para uma operação de conjuntos é igual a Empty ("").The value specified for a set operation is equal to Empty ("").

Não será possível alterar o valor dessa propriedade quando um email estiver sendo enviado.You cannot change the value of this property when an email is being sent.

Exemplos

O exemplo de código a seguir demonstra o envio de uma mensagem de email usando o host e a porta especificados em um arquivo de configuração de aplicativo.The following code example demonstrates sending an email message by using the host and port specified in an application configuration file.

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());
  }
}

Comentários

O valor da Host propriedade também pode ser definido usando construtores ou o arquivo de configuração do aplicativo ou da máquina.The value of the Host property can also be set using constructors or the application or machine configuration file. Para obter mais informações, consulte < > elemento MailSettings (configurações de rede).For more information, see <mailSettings> Element (Network Settings).

Se as informações forem especificadas usando essa propriedade, essas informações substituirão as configurações do arquivo de configuração.If information is specified using this property, this information overrides the configuration file settings.

Aplica-se a

Confira também