GroupDocsGists
10/24/2017 - 1:17 PM

Examples-CSharp-GroupDocs.Text.Examples.CSharp-EmailsExtractor-ExtractEmailAttachments.cs

// For complete examples and data files, please go to https://github.com/groupdocs-text/GroupDocs.Text-for-.NET
//get file actual path
String filePath = Common.getFilePath(fileName);
EmailTextExtractor extractor = new EmailTextExtractor(filePath);
ExtractorFactory factory = new ExtractorFactory();
for (int i = 0; i < extractor.AttachmentCount; i++)
{
    Console.WriteLine(extractor.GetContentType(i).Name);
    Stream stream = extractor.GetStream(i);
    TextExtractor attachmentExtractor = factory.CreateTextExtractor(filePath);
    try
    {
        Console.WriteLine(attachmentExtractor == null ? "Document format is not supported" : attachmentExtractor.ExtractAll());
    }
    finally
    {
        if (attachmentExtractor != null)
        {
            attachmentExtractor.Dispose();
        }
    }
}