MailMessage.Body プロパティ

定義

メッセージ本文を取得または設定します。

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

プロパティ値

本文テキストを格納している String 値。

次のコード例では、 プロパティの設定を Body 示します。

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

注釈

コンテンツの BodyContentType "text/plain" です。 プロパティを使用して本文に使用するエンコーディングを BodyEncoding 指定します。

本文コンテンツが、受信者により豊富なプレゼンテーション オプションを提供する代替形式で使用できる場合は、 プロパティを使用して本文コンテンツの代替ビューを AlternateViews 指定できます。 たとえば、アプリケーションでは、プレーン テキスト本文と HTML バージョンのメッセージ本文の両方を送信することを選択できます。 HTML を表示できるリーダー Email、本文の HTML バージョンを受信者に表示できますが、HTML を表示できないリーダーには、代わりにプレーン テキスト バージョンのメッセージが表示されます。

適用対象