:::: MENU ::::

Auto Download Full Items (VSTO Add-in for Outlook 2016)

This add-in will auto-download the full item of an email header in Outlook, if that email is less than 150kb. This is useful if you have a large Mailbox (50-100gb) and would like to cache all of the headers for search-ability, but want to be able to click on each message and auto-download on click, for convenience.

Download and install Visual Studio with the Office VSTO package. You can copy this code in and export your own vsto add-in for use. This is in C#.

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Threading;

namespace DownloadFullItems
{
    public partial class ThisAddIn
    {
        private Outlook.NameSpace outlookNameSpace;
        private Outlook.MAPIFolder inbox;
        private Outlook.Items items;
        private Outlook.Explorer currentExplorer;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            outlookNameSpace = this.Application.GetNamespace("MAPI");
            
            currentExplorer = this.Application.ActiveExplorer();
            currentExplorer.SelectionChange += new Outlook
                .ExplorerEvents_10_SelectionChangeEventHandler
                (CurrentExplorer_Event);

            void CurrentExplorer_Event()
            {
                    Outlook.Explorer selObject1 = new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer();
                    if (selObject1.Selection.Count > 0)
                    {
                        Object selObject = new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection[1];
                        if (selObject is Outlook.MailItem)
                        {
                            Outlook.MailItem mailItem3 = (selObject as Outlook.MailItem);
                            if (mailItem3.Size < 150000) mailItem3.Save();

                        }
                    }
                
                }
            
        }

            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Note: Outlook no longer raises this event. If you have code that 
            //    must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}