MailBee.NET Objects 3.1

MailMessage.EncodeAllHeaders Method 

Encodes all message headers into the specified encoding.

public void EncodeAllHeaders(
   Encoding targetEncoding,
   HeaderEncodingOptions options
);

Parameters

targetEncoding
The charset which is used to encode the value of the specified header.
options
The additional options which affect how the message headers are encoded.

Remarks

The developer should use this method before saving or sending an e-mail message if any message headers or attachment names contain international characters.

The developer can also encode custom header names using GetEncodedHeaderValue method.

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptiontargetEncoding is a null reference (Nothing in Visual Basic).

Example

This sample loads the message from .EML file, encodes it, and saves this message to disk.

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

// The actual code (put it into a method of your class).
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\source.eml");
msg.EncodeAllHeaders(Encoding.UTF8, HeaderEncodingOptions.Base64);
msg.SaveMessage(@"C:\Temp\result.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

' The actual code (put it into a method of your class).
Dim msg As New MailMessage
msg.LoadMessage("C:\Docs\source.eml")
msg.EncodeAllHeaders(Encoding.UTF8, HeaderEncodingOptions.Base64)
msg.SaveMessage("C:\Temp\result.eml")

See Also

MailMessage Class | MailBee.Mime Namespace | HeaderEncodingOptions