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