Load Email document with options

GroupDocs.Conversion provides the EmailLoadOptions class to give you control over how the source email document will be processed. The following options could be set:

OptionDescription
FormatThe document type is auto-detected during loading, however, you can specify explicitly the type of the source email document. Available options are: Msg, Eml, Emlx, Pst, Ost, Vcf, Mht 
ConvertOwned  Controls whether the owned documents in the documents container must be converted
ConvertOwner  Controls whether the documents container itself must be converted If this property is true the documents container will be the first converted document
Depth  Controls how many levels in depth to perform the conversion
DisplayBccEmailAddressOption to display or hide “Bcc” email address
DisplayCcEmailAddressOption to display or hide “Cc” email address
DisplayEmailAddresses Option to display or hide the email addresses next to the names, for example John Doe <john.doe@sample.com> or only John Doe. Default: true.
DisplayFromEmailAddressOption to display or hide “from” email address
DisplayHeaderOption to display or hide the email header
DisplayToEmailAddressOption to display or hide “to” email address
FieldTextMap The mapping between email message EmailField and field text representation
PreserveOriginalDate defines whether to keep the original date header string in the mail message when saving (Default value is true)
ExternalResourceHandlerA handler called for each resource the message asks to load; it can allow the resource, skip it or supply its content. Default: null. Available since version 26.10.
ResourceLoadingTimeoutSpecifies the timeout of loading the external resources.
SkipExternalResourcesWhether to skip the external resources the message references, such as remote images. Default: true. Content the message carries, local files inside its folder and resources that match WhitelistedResources still load. See Skip loading of external resources.
WhitelistedResourcesAbsolute URI prefixes, such as https://cdn.example.com/assets/, of external resources to load while SkipExternalResources is true. Since version 26.10, an entry that is not an absolute URI prefix makes the load fail with InvalidLoadOptionsException.
TimeZoneOffset Gets or sets the Coordinated Universal Time (UTC) offset for the message dates. This property defines the time zone difference, between the local time and UTC.

Control fields visibility

The following code snippet shows how to convert an Email document and control the visibility of the fields:

Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new EmailLoadOptions
{
    DisplayHeader = false,
    DisplayFromEmailAddress = false,
    DisplayToEmailAddress = false,
    DisplayCcEmailAddress = false,
    DisplayBccEmailAddress = false
};
using (Converter converter = new Converter("sample.msg", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Converting email attachments

The following code snippet shows how to convert an Email document and all attachments:

var source = "sample-with-attachment.eml";
var loadOptions = new EmailLoadOptions {
    ConvertOwner = true,
    ConvertOwned = true,
    // convert email itself and the attachments
    Depth = 2
};
using (var converter = new Converter(source, (LoadContext loadContext) => loadOptions))
{
    var index = 1;
    var options = new PdfConvertOptions();
    // Note: index = 1 is the email itself, all following indexes are attachments
    converter.Convert((SaveContext saveContext) => new FileStream($"converted-{index++}.{saveContext.TargetFormat.Extension}", FileMode.Create) , options);
}

Localize email fields captions

The following code snippet shows how to convert an Email document and localize the Email fields:

var source = "sample.eml";
var loadOptions = new EmailLoadOptions
{
    FieldTextMap = new Dictionary<EmailField, string>
    {
        { EmailField.Subject, "Gegenstand" },
        { EmailField.From, "Von" },
        { EmailField.Attachments, "Anhänge" }
    }
};
using (var converter = new Converter(source, (LoadContext loadContext) => loadOptions))
{
    var options = new PdfConvertOptions();
    converter.Convert("converted.pdf" , options);
}

Control date/time format

The following code snippet shows how to convert an Email document and modify the date/time format:

var source = "sample.eml";
CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
using (var converter = new Converter(source))
{
    var options = new PdfConvertOptions();
    converter.Convert("converted.pdf" , options);
}
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.