MailMessage.BodyEncoding 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用來對訊息主體進行編碼的編碼方式。
public:
property System::Text::Encoding ^ BodyEncoding { System::Text::Encoding ^ get(); void set(System::Text::Encoding ^ value); };
public System.Text.Encoding? BodyEncoding { get; set; }
public System.Text.Encoding BodyEncoding { get; set; }
member this.BodyEncoding : System.Text.Encoding with get, set
Public Property BodyEncoding As Encoding
屬性值
範例
下列程式代碼範例示範如何建立使用UTF8編碼的郵件訊息。
MailMessage^ message = gcnew MailMessage(from, to);
message->Body = "This is a test email message sent" +
" by an application. ";
// Include some non-ASCII characters in body and
// subject.
String^ someArrows = gcnew String(gcnew array<wchar_t>{L'\u2190',
L'\u2191', L'\u2192', L'\u2193'});
message->Body += Environment::NewLine + someArrows;
message->BodyEncoding = System::Text::Encoding::UTF8;
message->Subject = "test message 1" + someArrows;
message->SubjectEncoding = System::Text::Encoding::UTF8;
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] {'\u2190', '\u2191', '\u2192', '\u2193'});
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
Dim message As New MailMessage(mailFrom, mailTo)
message.Body = "This is a test email message sent by an application. "
' Include some non-ASCII characters in body and subject.
Dim someArrows As New String(New Char() {ChrW(&H2190), ChrW(&H2191), ChrW(&H2192), ChrW(&H2193)})
message.Body += Environment.NewLine & someArrows
message.BodyEncoding = System.Text.Encoding.UTF8
message.Subject = "test message 1" & someArrows
message.SubjectEncoding = System.Text.Encoding.UTF8
備註
為 BodyEncoding 屬性指定的值會設定 Content-Type 標頭中的字元集欄位。 預設字元集為 "us-ascii"
。
如果您將 BodyEncoding 屬性設定為UTF8、 Unicode或UTF32, 則 Framework 會為此 MailMessage選取 TransferEncoding 的 Base64 。