HeaderSet Value(String, String) Method
Set the header value using the specified charset.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public void SetValue(
string charset,
string value
)Parameters
Remarks
When a particular charset is desired for encoding the header value
according to the rules of rfc2047, this method should be used
instead of the Value setter.
Example
C#
public static void SetLatin1Subject (MimeMessage message)
{
var index = message.Headers.IndexOf (HeaderId.Subject);
Header subject;
if (index == -1) {
subject = new Header (HeaderId.Subject, string.Empty);
message.Headers.Add (subject);
} else {
subject = message.Headers[index];
}
// By default, MimeKit encodes non-ASCII header values using UTF-8. Some legacy mail
// clients may expect a specific charset, which can be specified via SetValue().
// The value will be serialized as: Subject: =?iso-8859-1?b?Q2Fm6Q==?= au lait
subject.SetValue ("iso-8859-1", "Café au lait");
// HeaderList.Replace() and Add() also have overloads that take an Encoding.
message.Headers.Replace (HeaderId.Comments, Encoding.UTF8, "Ça va?");
}
Exceptions
| ArgumentNullException |
charset is . -or- value is . |
| NotSupportedException | charset is not supported. |