MailMessage.Body Propriedade

Definição

Obtém ou define o corpo da mensagem.

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

Valor da propriedade

String

Um valor String que contém o texto do corpo.

Exemplos

O exemplo de código a seguir demonstra a configuração da Body propriedade.

static void CreateTestMessage2( String^ server )
{
   String^ to = L"jane@contoso.com";
   String^ from = 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.";
   SmtpClient^ client = gcnew SmtpClient( server );
   
   // Credentials are necessary if the server requires the client 
   // to authenticate before it will send email on the client's behalf.
   client->UseDefaultCredentials = true;
   client->Send( message );
   client->~SmtpClient();
}
public static void CreateTestMessage2(string server)
{
    string to = "jane@contoso.com";
    string from = "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.";
    SmtpClient client = new SmtpClient(server);
    // Credentials are necessary if the server requires the client
    // to authenticate before it will send email on the client's behalf.
    client.UseDefaultCredentials = true;

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
            ex.ToString());
    }
}
Public Shared Sub CreateTestMessage2(ByVal server As String)
    Dim [to] As String = "jane@contoso.com"
    Dim from As String = "ben@contoso.com"
    Dim message As MailMessage = 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."
    Dim client As SmtpClient = New SmtpClient(server)
    ' Credentials are necessary if the server requires the client
    ' to authenticate before it will send email on the client's behalf.
    client.UseDefaultCredentials = True

    Try
        client.Send(message)
    Catch ex As Exception
        Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString())
    End Try
End Sub

Comentários

O ContentType conteúdo Body é "text/plain". Especifique a codificação usada para o corpo com a BodyEncoding propriedade.

Se o conteúdo do corpo estiver disponível em formatos alternativos que fornecem opções de apresentação mais avançadas para os destinatários, você poderá especificar exibições alternativas para o conteúdo do corpo usando a AlternateViews propriedade. Por exemplo, um aplicativo pode optar por enviar o corpo do texto sem formatação e uma versão HTML do corpo da mensagem. Leitores de email que podem exibir HTML podem apresentar a versão HTML do corpo ao destinatário, enquanto os leitores que não puderem exibir HTML exibirão a versão de texto sem formatação da mensagem.

Aplica-se a