Использование ActiveInlineResponse во надстройке vsto. Отправить MailItem после изменения заголовка - PullRequest
0 голосов
/ 10 апреля 2020

Так что, когда сообщение «выскочило», и я использую инспектор, это работает нормально. Однако, с ActiveInlineResponse метод .Send () недоступен. К вашему сведению, я немного новичок, когда дело доходит до этого, но это действительно важно для приложения, которое мы внедряем. У меня есть та же надстройка в более ранней версии Office, которая прекрасно работает. Я не могу описать, как небольшая помощь могла бы сделать мой день здесь. Я потратил несколько часов на чтение сообщений на форуме, чтобы попытаться решить это самостоятельно, и у меня ничего не получается.

Несколько вопросов / вещей, которые я пробовал:

  • Я пытался сохранить элемент в черновиках и затем отправить его. Я не могу понять, как извлечь его из черновиков после его сохранения. Я пытался использовать EntryId, но мне не повезло.
  • Я пробовал несколько разных способов изменить Outlook.MailItem, чтобы разрешить метод Send (). Но безрезультатно.

Вот код:

        public void sendSecure_Click(Office.IRibbonControl control)
    {
        if (control.Id == "sendSecure" || control.Id == "inSendSecure")
        {
            Outlook.Explorer exp = Globals.SecMailAddIn.Application.ActiveExplorer();
            if(exp.ActiveInlineResponse != null)
            {
                if(exp.ActiveInlineResponse is Outlook.MailItem)
                {
                    Outlook.MailItem response = null;

                    response = exp.GetType().InvokeMember("ActiveInlineResponse",
                         System.Reflection.BindingFlags.GetProperty |
                         System.Reflection.BindingFlags.Instance |
                         System.Reflection.BindingFlags.Public,
                         null, exp, null) as Outlook.MailItem;

                    if (response != null)
                    {
                        //Add the property to the header, save them item and captuer the EntryID and close the item.
                        AddUserProperty(response, "XYZ");
                        ((Outlook._MailItem)response).Save();
                        var mailId = response.EntryID;
                        MessageBox.Show(mailId);


                        //Close the item
                        Marshal.ReleaseComObject(response);
                        Marshal.ReleaseComObject(exp);
                        //Send the Item Using the entryid.


                    }
                }
            }
            else
            {
                Outlook.Inspector oInspOriginal = control.Context as Outlook.Inspector;
                if (oInspOriginal.CurrentItem is Outlook.MailItem)
                {
                    Outlook.MailItem oMail = oInspOriginal.CurrentItem as Outlook.MailItem;
                    AddUserProperty(oMail, "XYZ");
                    ((Outlook._MailItem)oMail).Send();
                }
            }
        }
        else if (control.Id == "sendFullSecure" || control.Id == "inSendFullSecure")
        {
            Outlook.Inspector oInspOriginal = control.Context as Outlook.Inspector;
            if (oInspOriginal.CurrentItem is Outlook.MailItem)
            {
                Outlook.MailItem oMail = oInspOriginal.CurrentItem as Outlook.MailItem;
                AddUserProperty(oMail, "XYZZ");
                ((Outlook._MailItem)oMail).Send();
            }
        }
        else
        {
            Outlook.Inspector oInspOriginal = control.Context as Outlook.Inspector;
            if (oInspOriginal.CurrentItem is Outlook.MailItem)
            {
                Outlook.MailItem oMail = oInspOriginal.CurrentItem as Outlook.MailItem;
                AddUserProperty(oMail, "XYZZ");
                ((Outlook._MailItem)oMail).Send();
            }
        }
    }

    void Explorer_InlineResponseClose()
    {

    }

    private void AddUserProperty(Outlook.MailItem mail, string folderEmailId)
    {

        Outlook.PropertyAccessor mailPropertyAccessor = null;
        try
        {

            if (string.IsNullOrEmpty(folderEmailId))
                return;

            mailPropertyAccessor = mail.PropertyAccessor;
            mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId", folderEmailId);

            mail.Save();
        }
        catch (System.Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

РЕДАКТ. 1:

            else if (control.Id == "sendFullSecure" || control.Id == "inSendFullSecure")
        {
            Outlook.Explorer exp = Globals.SecMailAddIn.Application.ActiveExplorer();
            if (exp.ActiveInlineResponse != null)
            {
                if (exp.ActiveInlineResponse is Outlook.MailItem)
                {
                    Outlook.MailItem response = null;

                    response = exp.GetType().InvokeMember("ActiveInlineResponse",
                         System.Reflection.BindingFlags.GetProperty |
                         System.Reflection.BindingFlags.Instance |
                         System.Reflection.BindingFlags.Public,
                         null, exp, null) as Outlook.MailItem;
                    if (response != null)
                    {
                        try
                        {

                            //Add the property to the header.
                            AddUserProperty(response, "EBSENDSECURE");
                            //Get the Current Window Object
                            IOleWindow winh = exp as IOleWindow;
                            winh.GetWindow(out IntPtr win);
                            //Get the Handle from the window object. 
                            AutomationElement newElement = AutomationElement.FromHandle(win);
                            //Find the Standard Send Button Property and invoke it to send the email.  
                            PropertyCondition sendButtonCondition = new PropertyCondition(AutomationElement.NameProperty, "Send");
                            AutomationElement sendButton = newElement.FindFirst(TreeScope.Descendants, sendButtonCondition);
                            if (sendButton != null)
                            {
                                MessageBox.Show("The send button was found.");
                                var invokePattern = sendButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                                invokePattern.Invoke();
                            }
                            //Close the item
                            Marshal.ReleaseComObject(response);
                            Marshal.ReleaseComObject(exp);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("An error has occurred while sending this email.  Please close and reopen outlook to verify that it is sent correctly.");
                            throw;
                        }
                    }
                }
            }

1 Ответ

0 голосов
/ 10 апреля 2020

Да, OOM блокирует некоторые методы для встроенного ответа. Лучшее, что вы можете сделать, это смоделировать нажатие на кнопку «Отправить» с помощью API специальных возможностей.

Если используется параметр Погашение , он предоставляет SafeExplorer . ActiveInlineResponseSend Метод:

SafeExplorer sExplorer = new Redemption.SafeExplorer();
sExplorer.Item = Application.ActiveExplorer;
sExplorer.ActiveInlineResponseSend();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...