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
To view attachments just follow steps below:
- Instantiate Viewer object for the file that contains attachment(s);
- Call saveAttachment(…) method and save attachment (to local disk, memory stream, etc);
- Instantiate new Viewer object with previously saved attachment;
- Specify view options depending on desired output format - HtmlViewOptions / PngViewOptions / JpgViewOptions / PdfViewOptions;
- Call view(…) method.
Following code snippet demonstrates on how to view attachments from MSG file.
ByteArrayOutputStream attachmentStream = new ByteArrayOutputStream(); Viewer viewer = new Viewer("sample.msg"); viewer.saveAttachment("attachment-word.doc", attachmentStream); viewer.close(); Viewer viewer = new Viewer(new ByteArrayInputStream(attachmentStream.toByteArray())); HtmlViewOptions options = HtmlViewOptions.forEmbeddedResources(); viewer.view(options); viewer.close();
Advanced Usage Topics
To learn more about document viewing features, please refer to the advanced usage section.
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
- GroupDocs.Viewer for .NET samples, plugins and showcase
- Document Viewer for .NET MVC UI Example
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.