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 constructor is used:

Parser(string filePath, LoadOptions loadOptions);

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:

StringBuilder sb = new StringBuilder();
sb.AppendLine("mode = exchange");
sb.AppendLine("MailboxUri = https://outlook.office365.com/ews/exchange.asmx");
sb.AppendLine("Username = test@outlook.com");
sb.AppendLine("Password = password");

// Create an instance of Parser class to extract emails from the remote server
// As filePath connection parameters are passed; LoadOptions is set to Email file format
using(Parser parser = new Parser(sb.ToString(), new LoadOptions(FileFormat.Email)))
    // Check if container extraction is supported
        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());

The following connection parameters are used:

POPmode = pop
Host =
Port =
Username =
Password =

| | IMAP | mode = imap
Host =
Port =
Username =
Password =

| | EWS | mode = exchange
MailboxUri =
Username =
Password = |

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.