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
注解
ContentType内容Body为“text/plain”。 使用属性指定用于正文的 BodyEncoding 编码。
如果正文内容以为收件人提供更丰富的演示文稿选项的替代格式提供,则可以使用 AlternateViews 属性为正文内容指定备用视图。 例如,应用程序可以选择同时发送纯文本正文和 HTML 版本的消息正文。 可以显示 HTML 的电子邮件阅读器可以将正文的 HTML 版本呈现给收件人,而无法显示 HTML 的读者将改为显示邮件的纯文本版本。