Process the Microsoft Outlook Email Attachments in a .NET Viewer Application


An ‘attachment’ is a file such as a document or a photo that is attached to an email. It’s easy to attach pictures, files, contacts, emails and many other items to your Outlook messages. If you selected a file on your local computer or group document library for the attachment purpose, a copy of the file is attached to the email.

The case: A software developer is making a document viewing application. Although, his application is capable to render the MS Outlook Emails, but he also wants to add a feature to render the email attachments.

The GroupDocs.Viewer for .NET API for Processing Attachments

The GroupDocs.Viewer for .NET API provides the functionality to process attachments from document types that support them, e.g. Email documents, Outlook data files, Archives and PDF documents.

You’ll see in the below sections that how we can process the Microsoft Outlook Email attachments in various ways.

Render document attachments

To achieve this by using GroupDocs.Viewer for .NET you should:

  • Instantiate Viewer object for the initial document that contains attachment;
  • Call SaveAttachment method and save attachment somewhere (for example, to local disk or memory stream);
  • Instantiate another one Viewer object and path saved attachment to it;
  • Specify view options dependent on desired output format – HtmlViewOptions / PngViewOptions / JpgViewOptions / PdfViewOptions;
  • Call View method and render an attachment.

Following example demonstrates how to render document attachments.

Retrieve and print document attachments

GroupDocs.Viewer enables you to retrieve and print document attachments. The steps to get the list of all attachments are given below:

  • Instantiate Viewer object for the initial document that contains attachment;
  • Call GetAttachments method and obtain collection of document attachments ;
  • Iterate through attachments collection and print attachment names.

Following example demonstrates the implementation of the above steps.

Save document attachments

GroupDocs.Viewer enables you save document attachments to stream. Here are the steps for saving attachments:

  • Instantiate Viewer object for the initial document that contains attachment;
  • Call GetAttachments method and obtain collection of document attachments ;
  • Iterate through attachments collection and save attachment calling SaveAttachment method.

Following example demonstrates how to retrieve and save attachments.

The API offers many other handful features for your viewing applications. For more details, please feel free to visit documentation. To explore more examples you can access our open source examples and in case you would have any query, please feel to contact us using our forum.

Share on FacebookTweet about this on TwitterShare on LinkedIn