Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:15:37+00:00 2026-05-27T08:15:37+00:00

I really need help with this one. I have written an adding that adds

  • 0

I really need help with this one.

I have written an adding that adds a some text to the subject line of an email on send it also sets the same value in a property on the email through the PropertyAccessor. This works beautifully when the email is created through the Outlook interface.

The problem I have encountered is when a user is working with excel and decides to send the spreadsheet as an attachment from the Excel 2010 -> File -> Save & Send -> Send as Attachment Menu Item.

This will open the outlook 2010 mail editor as you would expect, the user can address the email and press send as normal and the email will be sent as normal. The problem is that the email editor does not close after sending as you would expect.

I am using the Globals.ThisAddIn.Application.ItemSend event to make my changes to the email. I notice also on debug that this event fires a couple of times when sending. The cancel argument of this event is always false during execution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:15:38+00:00Added an answer on May 27, 2026 at 8:15 am

    Finally found something that seems to work

    Developing an Inspector Wrapper for Outlook 2010

    In case the link goes dead as they are likely to do

    Here’s the wrapper

    namespace OutlookAddIn
    {
    // Eventhandler used to correctly clean up resources.
    // <param name="id">The unique id of the Inspector instance.</param>
    internal delegate void InspectorWrapperClosedEventHandler(Guid id);
    
    // The base class for all inspector wrappers.
    internal abstract class InspectorWrapper
    {
        // Event notification for the InspectorWrapper.Closed event.
        // This event is raised when an inspector has been closed.
    
        // The unique ID that identifies an inspector window.
        protected InspectorWrapper(Inspector inspector)
        {
            Id = Guid.NewGuid();
            Inspector = inspector;
            // Register Inspector events here
            ((InspectorEvents_10_Event) Inspector).Close += InspectorClose;
            ((InspectorEvents_10_Event) Inspector).Activate += Activate;
            (Inspector).Deactivate += Deactivate;
            (Inspector).BeforeMaximize += BeforeMaximize;
            (Inspector).BeforeMinimize += BeforeMinimize;
            (Inspector).BeforeMove += BeforeMove;
            (Inspector).BeforeSize += BeforeSize;
            (Inspector).PageChange += PageChange;
    
            // Initialize is called to give the derived wrappers.
            Initialize();
        }
    
        public Guid Id { get; private set; }
    
        // The Outlook Inspector instance.
        public Inspector Inspector { get; private set; }
        public event InspectorWrapperClosedEventHandler Closed;
    
        // .ctor
        // <param name="inspector">The Outlook Inspector instance that should be handled.</param>
    
        // Event handler for the Inspector Close event.
        private void InspectorClose()
        {
            // Call the Close Method - the derived classes can implement cleanup code
            // by overriding the Close method.
            Close();
    
            // Unregister Inspector events.
            ((InspectorEvents_10_Event) Inspector).Close -= InspectorClose;
    
            // Clean up resources and do a GC.Collect().
            Inspector = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
    
            // Raise the Close event.
            if (Closed != null)
            {
                Closed(Id);
            }
        }
    
        protected virtual void Initialize()
        {}
    
        // Method is called when another page of the inspector has been selected.
        // <param name="ActivePageName">The active page name by reference.</param>
        protected virtual void PageChange(ref string ActivePageName)
        {}
    
        // Method is called before the inspector is resized.
        // <param name="Cancel">To prevent resizing, set Cancel to true.</param>
        protected virtual void BeforeSize(ref bool Cancel)
        {}
    
        // Method is called before the inspector is moved around.
        // <param name="Cancel">To prevent moving, set Cancel to true.</param>
        protected virtual void BeforeMove(ref bool Cancel)
        {}
    
        // Method is called before the inspector is minimized.
        // <param name="Cancel">To prevent minimizing, set Cancel to true.</param>
        protected virtual void BeforeMinimize(ref bool Cancel)
        {}
    
        // Method is called before the inspector is maximized.
        // <param name="Cancel">To prevent maximizing, set Cancel to true.</param>
        protected virtual void BeforeMaximize(ref bool Cancel)
        {}
    
        // Method is called when the inspector is deactivated.
        protected virtual void Deactivate()
        {}
    
        // Method is called when the inspector is activated.
        protected virtual void Activate()
        {}
    
        // Derived classes can do a cleanup by overriding this method.
        protected virtual void Close()
        {}
    
    
        // This factory method returns a specific InspectorWrapper or null if not handled.
        // <param name=”inspector”>The Outlook Inspector instance.</param>
        // Returns the specific wrapper or null.
        public static InspectorWrapper GetWrapperFor(Inspector inspector)
        {
            // Retrieve the message class by using late binding.
            string messageClass = inspector.CurrentItem.GetType().InvokeMember("MessageClass", BindingFlags.GetProperty,
                                                                               null, inspector.CurrentItem, null);
    
            // Depending on the message class, you can instantiate a
            // different wrapper explicitly for a given message class by
            // using a switch statement.
            switch (messageClass)
            {
                case "IPM.Contact":
                    return new ContactItemWrapper(inspector);
                case "IPM.Journal":
                    return new ContactItemWrapper(inspector);
                case "IPM.Note":
                    return new MailItemWrapper(inspector);
                case "IPM.Post":
                    return new PostItemWrapper(inspector);
                case "IPM.Task":
                    return new TaskItemWrapper(inspector);
            }
    
            // Or, check if the message class begins with a specific fragment.
            if (messageClass.StartsWith("IPM.Contact.X4U"))
            {
                return new X4UContactItemWrapper(inspector);
            }
    
            // Or, check the interface type of the item.
            if (inspector.CurrentItem is AppointmentItem)
            {
                return new AppointmentItemWrapper(inspector);
            }
    
            // No wrapper is found.
            return null;
        }
    }
    
    // Derive a wrapper for each message class/item type.
    }
    

    and here is an example override

    internal class MailItemWrapper : InspectorWrapper
    {
        // The Object instance behind the Inspector, which is the current item.
    
        public MailItemWrapper(Inspector inspector)
            : base(inspector)
        {
            // Get the item in the current Inspector.
            Item = (MailItem) Inspector.CurrentItem;
    
            // Register Item events.
            Item.Open += Item_Open;
            Item.Write += Item_Write;
        }
    
        public MailItem Item { get; private set; }
    
        // This method is called when the item is visible and the UI is initialized.
        // <param name="Cancel">When you set this property to true, the Inspector is closed.</param>
        private void Item_Open(ref bool Cancel)
        {
            // TODO: Implement something 
        }
    
        // This method is called when the item is saved.
        // <param name="Cancel">When set to true, the save operation is cancelled.</param>
        private void Item_Write(ref bool Cancel)
        {
            //TODO: Implement something 
        }
    
        // The Close method is called when the inspector has been closed.
        // Do your cleanup tasks here.
        // The UI is gone, cannot access it here.
        protected override void Close()
        {
            // Unregister events.
            Item.Write -= Item_Write;
            Item.Open -= Item_Open;
    
            // Release references to COM objects.
            Item = null;
    
            // Set item to null to keep a reference in memory of the garbage collector.
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
    

    and here is the ThisAddin class

    public partial class ThisAddIn
    {
        // Holds a reference to the Application.Inspectors collection.
        // Required to get notifications for NewInspector events.
        private Inspectors _inspectors;
    
        // A dictionary that holds a reference to the inspectors handled by the add-in.
        private Dictionary<Guid, InspectorWrapper> _wrappedInspectors;
    
        private void ThisAddInStartup(object sender, EventArgs e)
        {
            _wrappedInspectors = new Dictionary<Guid, InspectorWrapper>();
            _inspectors = Globals.ThisAddIn.Application.Inspectors;
            _inspectors.NewInspector += WrapInspector;
    
            // Also handle existing Inspectors
            // (for example, double-clicking a .msg file).
            foreach (Inspector inspector in _inspectors)
            {
                WrapInspector(inspector);
            }
        }
    
    
        // Wrap an Inspector, if required, and store it in memory to get events of the wrapped Inspector.
        // <param name="inspector">The Outlook Inspector instance.</param>
        private void WrapInspector(Inspector inspector)
        {
            var wrapper = InspectorWrapper.GetWrapperFor(inspector);
            if (wrapper != null)
            {
                // Register the Closed event.
                wrapper.Closed += WrapperClosed;
                // Remember the inspector in memory.
                _wrappedInspectors[wrapper.Id] = wrapper;
            }
        }
    
        // Method is called when an inspector has been closed.
        // Removes reference from memory.
        // <param name="id">The unique id of the closed inspector</param>
        private void WrapperClosed(Guid id)
        {
            _wrappedInspectors.Remove(id);
        }
    
    
        private void ThisAddInShutdown(object sender, EventArgs e)
        {
            // Clean up.
            _wrappedInspectors.Clear();
            _inspectors.NewInspector -= WrapInspector;
            _inspectors = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    
        #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()
        {
            Startup += ThisAddInStartup;
            Shutdown += ThisAddInShutdown;
        }
    
        #endregion
    }
    

    There should be enough there to get people out of trouble if the link is down

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really need some help with this as I have been trying to fix
I really need help on this one. I am having a simple login form
I've some questions .. and I really need your help. I have an application.
Good day. I could really use your help on this one. I have a
I really need some help. I have a List which has 4 columns and
Sorry to bother again, but I really need help transforming this Python2 code into
I really need your help for this. I am relatively new to programming and
I really need help with interfaces in general... Any resources that you guys would
Well, I know absolutely nothing about the subject, so I really need help. I
I really need some help in Regular Expressions, i'm working on a function like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.