Nilesh Pegasus
Nilesh Pegasus

Reputation: 13

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);
                    }
                }
            }

Upvotes: 1

Views: 192

Answers (3)

Shyam sundar shah
Shyam sundar shah

Reputation: 2523

You can send inlineresponse pragamatically using following code. You can not use inlineresponse.Send() method. You need to first get inlineresponse. Then get inspector and then activate it and then save mailitem and send it. It is working as expected

        Outlook.MailItem inlineResponse = null;
        Outlook.Inspector inspector = null;
        Outlook.MailItem mailItemFromInspector = null;
        Outlook.Explorer explorer 
        = Globals.ThisAddIn.Application.ActiveExplorer()
        try
        {
            if (explorer.ActiveInlineResponse != null)
            {
                inlineResponse = explorer.ActiveInlineResponse;
                inspector = inlineResponse.GetInspector;
                inspector.Activate();
                mailItemFromInspector = inspector.CurrentItem;
                mailItemFromInspector.Save();
                mailItemFromInspector.Send();
            }
            
        }
        catch (Exception ex)
        {
            //write log message here
        }
        finally
        {
             Marshal.ReleaseComObject(mailItemFromInspector);
             Marshal.ReleaseComObject(inspector);
             Marshal.ReleaseComObject(inlineResponse);
        }

Upvotes: 0

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

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();

Upvotes: 0

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

The Explorer.ActiveInlineResponse property returns an item object representing the active inline response item in the explorer reading pane. You ca use the same properties and methods of the MailItem object on this item, except for the following:

  • MailItem.Actions property
  • MailItem.Close method
  • MailItem.Copy method
  • MailItem.Delete method
  • MailItem.Forward method
  • MailItem.Move method
  • MailItem.Reply method
  • MailItem.ReplyAll method
  • MailItem.Send method

As you can see the Send method is not supported on the inline response items in Outlook.

As a possible workaround you may call the Display method which can open the item in a new inspector window where you could get the instance and call the Send method. The NewInspector event is fired whenever a new inspector window is opened, either as a result of user action or through program code. But I'd suggest getting the Inspector.Activate event fired to get the MailItem instance and call the Send method.

Upvotes: 0

Related Questions