Прочетете на английски Редактиране

Споделяне чрез


MailMessage.BodyEncoding Property

Definition

Gets or sets the encoding used to encode the message body.

C#
public System.Text.Encoding? BodyEncoding { get; set; }
C#
public System.Text.Encoding BodyEncoding { get; set; }

Property Value

An Encoding applied to the contents of the Body.

Examples

The following code example demonstrates creating a mail message that uses UTF8 encoding.

C#
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;

Remarks

The value specified for the BodyEncoding property sets the character set field in the Content-Type header. The default character set is "us-ascii".

If you set the BodyEncoding property to UTF8, Unicode, or UTF32, the Framework selects a TransferEncoding of Base64 for this MailMessage.

Applies to

Продукт Версии
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also