outlookoffice365vstooutlook-addinoffice-addins

Is there any way to call send method on email opened in inline reply based on custom send button click


I have found a similar post by another user. https://stackoverflow.com/questions/61183940/is-there-any-way-to-call-send-method-on-composed-mail-opened-in-inline-reply-bas

which is answered, But the page which has answer is no longer active https://stackoverflow.com/questions/61142613/using-activeinlineresponse-in-vsto-add-in-send-mailitem-after-modifying-header/61144021#comment108226887_61144021

Tried noting as such
Edit : I did call the Item.Send in the Inspector Activate event.. and new inspector event where i call the activate method. But the window does not disappear unless I click on the window icon in the task bar [to bring it to focus.].

void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
        Base objBase = new Base();
        dynamic mailItem = objBase.GetItemObject(Inspector.CurrentItem);

        var inspector = Inspector as Outlook.InspectorEvents_10_Event;
        if (inspector != null)
        {
            inspector.Close += Inspectors_CloseInspector;
        }
        if (mailItem != null)
        {
            //if (mailItem.EntryID == null)
            //{
            if (mailItem is Outlook.MailItem)
            {
                if (IsInlineItem)
                {

                    _MailItem = mailItem;
                    ((Outlook.InspectorEvents_Event)Inspector).Activate += new Outlook.InspectorEvents_ActivateEventHandler(InspectorActivate);
                    ((Outlook.InspectorEvents_Event)Inspector).Deactivate += new Outlook.InspectorEvents_DeactivateEventHandler(InspectorDeactivate);
                    ((Outlook.InspectorEvents_Event)Inspector).Close += new Outlook.InspectorEvents_CloseEventHandler(Inspectors_CloseInspector);
                    Inspector.Activate();

                }
                else if (mailItem.Sent == false)
                { _MailItem = mailItem; }
                else
                {
                    Marshal.ReleaseComObject(mailItem);
                }


            }
            else
            {
                _MailItem = mailItem;
                Marshal.ReleaseComObject(mailItem);
            }
            //}

        }

       
        objBase.WriteError("new Inspector");
    }






 private void InspectorActivate()
        {
            Base objBase = new Base();
            Outlook.Inspector ActiveInspector = Application.ActiveInspector();
            if (ActiveInspector is null)
            {

            }
            else
            {
                //Base objBase = new Base();
                dynamic selectedItem = objBase.GetItemObject(ActiveInspector.CurrentItem);
                if (selectedItem != null && _MailItem.Subject == selectedItem.Subject && selectedItem.Sent == false)
                {
                    try
                    {
                        selectedItem.Send();
                       
                       
                    }
                    catch (Exception e)
                    {

                    }
                    finally
                    {
                        Marshal.ReleaseComObject(selectedItem);
                        Marshal.ReleaseComObject(ActiveInspector);
                    }
                }
            }

Solution

  • That question got deleted. I will repost the answer:

    Yes, OOM blocks some methods for the inline response. The best you can do is simulate a click on the Send button using the accessibility API.

    If using Redemption is an option (I am its author), it exposes SafeExplorer.ActiveInlineResponseSend method:

    SafeExplorer sExplorer = new Redemption.SafeExplorer();
    sExplorer.Item = Application.ActiveExplorer;
    sExplorer.ActiveInlineResponseSend();