How to list attachments

Extracting attachments

GroupDocs.Viewer for Java API enables you to retrieve a list of document attachments from your emails, Outlook data files, archives and PDF documents.

Follow these steps to get a list of all attachments:

  • Instantiate Viewer object for the file that contains attachment(s);
  • Call getAttachments() method which will return document attachments collection;
  • Iterate through attachments collection.

Following example demonstrates on how to get all attachments from MSG file.

    try (Viewer viewer = new Viewer("sample.msg")) {
        List<Attachment> attachments = viewer.getAttachments();
        for (Attachment attachment : attachments) {

More resources

Advanced Usage Topics

To learn more about document viewing features, please refer to the advanced usage section.

GitHub Examples

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

Free Online App

Along with full-featured Java library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.