Load Email document with options

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

  • Format - the 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 
  • DisplayHeader - option to display or hide the email header
  • DisplayFromEmailAddress - option to display or hide “from” email address
  • DisplayEmailAddress - option to display or hide email address
  • DisplayToEmailAddress  - option to display or hide “to” email address
  • DisplayCcEmailAddress - option to display or hide “Cc” email address
  • DisplayBccEmailAddress - option to display or hide “Bcc” email address
  • 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 conversion
  • FieldTextMap - the mapping between email message EmailField and field text representation
  • PreserveOriginalDate - defines whether need to keep original date header string in mail message when saving or not (Default value is true)
  • TimeZoneOffset - gets or sets the Coordinated Universal Time (UTC) offset for the message dates. This property defines the time zone difference, between the localtime and UTC.

Control fields visibility

The following code sample shows how to convert Email document and control the fields visibility:

Contracts.Func<LoadOptions> getLoadOptions = () => new EmailLoadOptions
{
    DisplayHeader = false,
    DisplayFromEmailAddress = false,
    DisplayToEmailAddress = false,
    DisplayEmailAddress = 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 sample shows how to convert 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, () => loadOptions))
{
    var index = 1;
    var options = new PdfConvertOptions();
    // Note: index = 1 is the email itself, all following indexes are attachments
    converter.Convert(() => new FileStream($"converted-{index++}.pdf", FileMode.Create) , options);
}

Localize email fields captions

The following code sample shows how to convert Email document and localize 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, () => loadOptions))
{
    var options = new PdfConvertOptions();
    converter.Convert("converted.pdf" , options);
}


Control date/time format

The following code sample shows how to convert Email document and modify 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);
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Document Converter Apps

Along with full-featured .NET library we provide free Apps and free services for document conversion. In order to see a full potential of GroupDocs.Conversion, you are welcome to convert DOC to PDF, DOC to XLSX, PDF to DOC, PDF to XLSX, PPT to DOC and more with Free Online Document Converter App or get a full advantage of Free Online Document Converter Suite with advanced conversion settings and many more enterprise built-in features.

Please note that more premium features, advanced options and enhanced document management experience is available for signed-in users at conholdate.app for FREE.
If you don’t own an account yet, register it now for free! No credit card is required!