在 vsto 插件中使用 ActiveInlineResponse.修改标题后发送MailItem [英] Using ActiveInlineResponse in vsto Add-In. Send MailItem after modifying header

查看:77
本文介绍了在 vsto 插件中使用 ActiveInlineResponse.修改标题后发送MailItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当消息弹出"并且我使用检查器时,这工作正常.然而,对于 ActiveInlineResponse,.Send() 方法不可用.仅供参考,我在这方面有点新手,但这对于我们正在推出的应用程序非常重要.我在早期版本的 Office 中有相同的加载项,效果很好.我无法描述一点点帮助会让我在这里度过多少日子.我花了好几个小时阅读论坛帖子来尝试自己解决这个问题,但我失败了.

So when the message is "popped out" and I use the inspector this works fine. HOwever, with the ActiveInlineResponse the .Send() method is not available. FYI I am a bit of a novice when it comes to this but this is really important for an application we are rolling out. I have the same Add-IN in earlier version of Office that work great. I can't describe how much a little assistance would make my day here. I have spent multiple hours reading forum posts to try and work this out on my own and I am failing.

我尝试过的一些问题/事情:

A few questions/things I have tried:

  • 我尝试将项目保存为草稿,然后再发送.保存后,我似乎无法弄清楚如何从草稿中取出它.我曾尝试使用 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;
                        }
                    }
                }
            }

推荐答案

是的,OOM 阻止了一些用于内联响应的方法.您能做的最好的事情是使用辅助功能 API 模拟单击​​发送"按钮.

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.

如果使用 Redemption 是一种选择,它会暴露 SafeExplorer.ActiveInlineResponseSend 方法:

If using Redemption is an option, it exposes SafeExplorer.ActiveInlineResponseSend method:

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

这篇关于在 vsto 插件中使用 ActiveInlineResponse.修改标题后发送MailItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆