MailMessage.Body プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
メッセージ本文を取得または設定します。
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 プロパティの設定を示しています。
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
注釈
Body コンテンツのContentTypeは "text/plain" です。 BodyEncoding プロパティを使用して本文に使用するエンコーディングを指定します。
本文のコンテンツが、受信者により豊富なプレゼンテーション オプションを提供する代替形式で使用できる場合は、 AlternateViews プロパティを使用して、本文コンテンツの代替ビューを指定できます。 たとえば、アプリケーションは、プレーン テキスト本文とメッセージ本文の HTML バージョンの両方を送信することを選択できます。 HTML を表示できる電子メール リーダーは、本文の HTML バージョンを受信者に提示できますが、HTML を表示できない閲覧者は代わりにテキスト形式のメッセージを表示します。