Extract emails from remote server via POP IMAP or Exchange Web Services protocols

GroupDocs.Parser allows you to extract emails from remote servers and data from the emails. The following email protocols are supported:

  • Post Office Protocol (POP)
  • Internet Message Access Protocol (IMAP)
  • Exchange Web Services (EWS)

To create an instance of Parser class to extract emails from a remote server the following constructors are used:

Parser(EmailConnection connection);
Parser(EmailConnection connection, ParserSettings parserSettings);

The second constructor allows to use ParserSettings object to control the process; for example, by adding logging functionality.

EmailConnection is a base class. The following connection classes are used:

Exchange Web ServicesEmailEwsConnection

Here are the steps to extract emails from the remote server:

  • Prepare connection string (see table below);
  • Instantiate Parser object with connection string;
  • Call Features.Container property to check if container extraction is supported;
  • Call GetContainer method and obtain collection of document container item objects;
  • Iterate through the collection and get Parser object for each item.

The following example shows how to extract emails from Exchange Server:

// Create the connection object for Exchange Web Services protocol 
EmailConnection connection = new EmailEwsConnection(
// Create an instance of Parser class to extract emails from the remote server
using (Parser parser = new Parser(connection))
    // Check if container extraction is supported
    if (!parser.Features.Container)
        Console.WriteLine("Container extraction isn't supported.");
    // Extract email messages from the server
    IEnumerable<ContainerItem> emails = parser.GetContainer();
    // Iterate over attachments
    foreach (ContainerItem item in emails)
        // Create an instance of Parser class for email message
        using (Parser emailParser = item.OpenParser())
            // Extract the email text
            using (TextReader reader = emailParser.GetText())
                // Print the email text
                Console.WriteLine(reader == null ? "Text extraction isn't supported." : reader.ReadToEnd());

More resources

GitHub examples

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

Free online document parser App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.