How to convert and view attachments

View email/file attachments in the same way as you would view any other documents.

There are many different use cases when you need to view/preview attachments form an emails, save attachments to specific location, parse or extract attachments. So we made this process easy and simple with GroupDocs.Viewer for Java API.

GroupDocs.Viewer supports attachments from following formats:

  • Email attachments
  • Outlook attachments
  • Archives
  • PDF

To view attachments just follow steps below:

Following code snippet demonstrates on how to view attachments from MSG file.

    ByteArrayOutputStream attachmentStream = new ByteArrayOutputStream()

    try (Viewer viewer = new Viewer("sample.msg")) {
        viewer.saveAttachment("attachment-word.doc", attachmentStream);
    try (Viewer viewer = new Viewer(new ByteArrayInputStream(attachmentStream.toByteArray()))) {
        HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources();

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.