Class MsgLoadOptions

MsgLoadOptions class

Provides options for controlling how MailMessage instances are loaded from MSG format. This class allows you to customize the loading behavior for Outlook MSG files, including TNEF attachment handling, RTF body preservation, email address preservation, and timeout configuration.

public class MsgLoadOptions : LoadOptions

Constructors

NameDescription
MsgLoadOptions()Initializes a new instance of this class that can be used to loading MailMessage from Msg format.

Properties

NameDescription
KeepOriginalEmailAddresses { get; set; }Gets or sets a value indicating whether need keep original email address.
MessageFormat { get; }Represents the mail message format.It can be in eml,msg or mhtml format. The default value is Eml.
PreferredTextEncoding { get; set; }Gets or sets preferred encoding for message. Forcibly sets the preferred encoding for message subject and body. The default value is null.
PreserveEmbeddedMessageFormat { get; set; }Gets or sets a value indicating whether it is necessary to preserve format of embedded message at loading. By default the value is false.
PreserveRtfContent { get; set; }Gets or sets a value indicating whether need keep rtf body in MailMessage.
PreserveTnefAttachments { get; set; }Controls loading TNEF attachment behaviour. By default the value is false.
RemoveSignature { get; set; }Gets or sets a value indicating whether signature will be removed while loading.
Timeout { get; set; }Limits the time in milliseconds of formatting message while converting. Default value 3 sec.

Events

NameDescription
event TimeoutReachedRaised if timed out while converting to MailMessage.

Remarks

Use this class with Load to load Outlook MSG files and control various loading options. MSG is the native format for Outlook messages and can contain various Outlook-specific features. The PreserveTnefAttachments property controls TNEF handling, PreserveRtfContent preserves RTF body formatting, and Timeout limits the conversion time.

Examples

The following example shows how to use MsgLoadOptions to load an Outlook MSG file with custom settings.

[C#]

// Create MSG load options with custom settings
var loadOptions = new MsgLoadOptions()
{
    PreserveTnefAttachments = true,
    PreserveRtfContent = true,
    KeepOriginalEmailAddresses = true,
    Timeout = 5000
};

// Handle timeout event
loadOptions.TimeoutReached += (sender, e) =>
{
    Console.WriteLine("Message loading timed out");
};

// Load MSG file with custom options
using (MailMessage message = MailMessage.Load("message.msg", loadOptions))
{
    // Convert to EML format
    message.Save("output.eml", SaveOptions.DefaultEml);
}

[Visual Basic]

' Create MSG load options with custom settings
Dim loadOptions As New MsgLoadOptions() With {
    .PreserveTnefAttachments = True,
    .PreserveRtfContent = True,
    .KeepOriginalEmailAddresses = True,
    .Timeout = 5000
}

' Handle timeout event
AddHandler loadOptions.TimeoutReached, Sub(sender, e)
                                            Console.WriteLine("Message loading timed out")
                                        End Sub

' Load MSG file with custom options
Using message As MailMessage = MailMessage.Load("message.msg", loadOptions)
    ' Convert to EML format
    message.Save("output.eml", SaveOptions.DefaultEml)
End Using

See Also