Extract metadata from Emails

To extract metadata from emails getMetadata method is used. This method allows to extract the following metadata:

NameDescription
subjectThe email “subject” field.
email-senderThe email “from” field.
email-toThe email “to” field. May contain more than one address separated by semicolons.
email-ccThe email “cc” field. May contain more than one address separated by semicolons.

Here are the steps to extract metadata from an email:

  • Instantiate Parser object for the initial email;
  • Call getMetadata method and obtain collection of document metadata objects;
  • Iterate through the collection and get metadata names and values.

The following example demonstrates how to extract metadata from an email:

// Create an instance of Parser class
try (Parser parser = new Parser(Constants.SampleMsg)) {
    // Extract metadata from the email
    Iterable<MetadataItem> metadata = parser.getMetadata();
    // Iterate over metadata items
    for (MetadataItem item : metadata) {
        // Print an item name and value
        System.out.println(String.format("%s: %s", item.getName(), item.getValue()));
    }
}

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.