MailBee.NET Objects 3.1

MailMessage.GetEncodedHeaderValue Method 

Encodes the value of the specified header.

public static string GetEncodedHeaderValue(
   string headerName,
   string headerValue,
   Encoding targetEncoding,
   HeaderEncodingOptions options
);

Parameters

headerName
The name of the header.
headerValue
The value of the header.
targetEncoding
The charset which is used to encode the value of the specified header.
options
The additional options which affect how the header is encoded.

Return Value

A string containing the encoded value of the header.

Exceptions

Exception Type Condition
MailBeeInvalidArgumentException headerName or headerValue or targetEncoding is a null reference (Nothing in Visual Basic).

Example

This sample encodes Subject header into UTF-8 (Quoted-Printable version) and save the message into a file.

[C#]
// To use the code below, import the following namespaces at the top of your code.
using System.Text;
using MailBee;
using MailBee.Mime;

MailMessage msg = new MailMessage();
msg.Subject = MailMessage.GetEncodedHeaderValue("Subject", "Any text here", Encoding.UTF8, HeaderEncodingOptions.ForceEncoding | HeaderEncodingOptions.Base64);
msg.SaveMessage(@"C:\Temp\msg.eml");
[Visual basic]
' To use the code below, import the following namespaces at the top of your code.
Imports System.Text
Imports MailBee
Imports MailBee.Mime

Dim msg As New MailMessage
msg.Subject = MailMessage.GetEncodedHeaderValue("Subject", "Any text here", Encoding.UTF8, HeaderEncodingOptions.ForceEncoding Or HeaderEncodingOptions.Base64)
msg.SaveMessage("C:\Temp\msg.eml")

See Also

MailMessage Class | MailBee.Mime Namespace | HeaderEncodingOptions