Outlook add-in for automatic email archiving to PDF

Project overview

I built a VSTO add-in for Microsoft Outlook that watches one selected mailbox and turns every incoming message into a single PDF document, attachments included, then sends it into the client's business system. The user does nothing: mail arrives as it always did, while archiving happens in the background, inside the program employees keep open all day anyway.

The engineering challenge

The hard part was not producing the PDF but catching the message reliably. The Outlook new-mail event can report several messages at once, can fire before a message has been fully downloaded from the server and, in unlucky cases, can fire twice for the same message. On top of that, working with Outlook objects has to stay on the main thread, while building a PDF and uploading it take far too long to be done there — otherwise the program would freeze while the user is typing a reply.

The second challenge was the attachments. PDF files arriving by mail are often damaged or produced by tools that ignore the standard, so the merging library rejects them. The solution had to accept them rather than stop at the first malformed document.

How the solution is organised

  • One mailbox is watched – the add-in follows exactly the mailbox selected in its settings and leaves messages from other accounts in the same Outlook profile alone.
  • A stable message key – recognition relies on the standard message identifier read directly from MAPI properties. When the identifier has not arrived yet, the add-in waits and tries again, and as a last resort computes a fingerprint from sender, subject and time of receipt. No message is ever processed twice.
  • Work split across threads – reading the message and its attachments stays on the main thread, where Outlook demands it, while PDF creation and upload run asynchronously. The number of concurrent jobs is capped, so the add-in does not overload the machine when several messages land at once.
  • One document instead of a pile of files – the message body is turned into HTML with a header (sender, recipients, time, subject), images embedded from the message itself and attachments rendered inline, and all of it is printed to PDF. Attached PDF documents are merged into the same file, and formats that cannot be rendered are listed by name, so nothing silently disappears.
  • Repair of malformed PDF attachments – before merging, every attached PDF goes through a repair tool, in two passes with different options. If neither works, the original is used and the job carries on.
  • A switch in the Outlook ribbon – a dedicated tab with an enable checkbox and a settings button. Turning it off also stops jobs already in flight, through cancellation tokens.
  • Settings that explain themselves – every setting carries its description in a separate file, so the dialog states what each field means without a separate manual.

Reliability and edge cases

The attention went into details that only show up in daily use: releasing COM objects properly so Outlook does not linger in memory, time limits for the external tools, deleting temporary files after every job, and a log entry for each stage — from picking up the message to confirmation that the document was received. When an upload fails, the error is recorded and it is clear which message did not go through, instead of vanishing in silence.

A version upgrade keeps the settings entered earlier, so nobody has to configure anything again after an update.

Technologies used

C#, .NET Framework 4.8, Outlook VSTO add-in, Outlook Interop and MAPI properties, custom ribbon (Ribbon XML), asynchronous programming with capped concurrency and cancellation tokens, PDF generation from HTML, merging and repair of PDF documents, HTTP/JSON communication with a backend system.

Outcome

The client got archiving that does not depend on staff discipline. A message and its attachments end up as one document in the business system the moment they arrive, with no downloading, printing to PDF and manual attaching. The add-in works quietly, can be switched off with one click and changes nothing about how people use Outlook.

Client feedback

★★★★★5/5

“Dejan has been excellent to work with. He is professional, reliable and highly skilled, consistently delivering high-quality work on time. He communicates clearly, responds quickly to feedback and demonstrates a strong understanding of the project requirements. I would be very happy to continue working with him and highly recommend him to other clients.”

For a similar add-in in Excel, Word or Outlook, see the custom software development service.