VintaSoft Imaging .NET SDK 15.2: Documentation for .NET developer
Vintasoft.Imaging.Email Namespace / EmailDocumentConverter Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
EmailDocumentConverter Class
In This Topic
Contains methods, which allows to convert Email (.msg, .eml) document.
Object Model
EmailDocumentConverter
Syntax
'Declaration

Public MustInherit NotInheritable Class EmailDocumentConverter

public static class EmailDocumentConverter

Example

This C#/VB.NET code shows how to convert Email document to a DOCX document.


''' <summary>
''' Converts Email (.msg, .eml) document to a DOCX document.
''' </summary>
''' <param name="emailFilePath">Path to a source Email file.</param>
''' <param name="docxFilePath">Path to a result DOCX file.</param>
Public Shared Sub ConvertEmailToDocx(emailFilePath As String, docxFilePath As String)
    docxFilePath = System.IO.Path.GetFullPath(docxFilePath)
    Dim tempHtmlFilename As String = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(docxFilePath), System.IO.Path.GetFileNameWithoutExtension(docxFilePath) & ".html")

    ' directory to save attachments
    Dim attachmentsDirectoryName As String = System.IO.Path.GetFileNameWithoutExtension(docxFilePath) & ".files"

    ' convert Email document to a HTML document
    Vintasoft.Imaging.Email.EmailDocumentConverter.ConvertEmailToHtml(emailFilePath, tempHtmlFilename, attachmentsDirectoryName, New Vintasoft.Imaging.Email.EmailToHtmlConverterSettings())

    ' convert HTML document to a DOCX document
    Vintasoft.Imaging.Office.OpenXml.OpenXmlDocumentConverter.ConvertHtmlToDocx(tempHtmlFilename, docxFilePath)

    ' delete temp HTML filename
    System.IO.File.Delete(tempHtmlFilename)
End Sub


/// <summary>
/// Converts Email (.msg, .eml) document to a DOCX document.
/// </summary>
/// <param name="emailFilePath">Path to a source Email file.</param>
/// <param name="docxFilePath">Path to a result DOCX file.</param>
public static void ConvertEmailToDocx(string emailFilePath, string docxFilePath)
{
    docxFilePath = System.IO.Path.GetFullPath(docxFilePath);
    string tempHtmlFilename = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(docxFilePath), 
        System.IO.Path.GetFileNameWithoutExtension(docxFilePath) + ".html");

    // directory to save attachments
    string attachmentsDirectoryName = System.IO.Path.GetFileNameWithoutExtension(docxFilePath) + ".files";

    // convert Email document to a HTML document
    Vintasoft.Imaging.Email.EmailDocumentConverter.ConvertEmailToHtml(
        emailFilePath, tempHtmlFilename, attachmentsDirectoryName, new Vintasoft.Imaging.Email.EmailToHtmlConverterSettings());

    // convert HTML document to a DOCX document
    Vintasoft.Imaging.Office.OpenXml.OpenXmlDocumentConverter.ConvertHtmlToDocx(tempHtmlFilename, docxFilePath);

    // delete temp HTML filename
    System.IO.File.Delete(tempHtmlFilename);
}

Inheritance Hierarchy

System.Object
   Vintasoft.Imaging.Email.EmailDocumentConverter

Requirements

Target Platforms: .NET 11; .NET 10; .NET 9; .NET 8; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also