-->

以编程方式使用加密督察Outlook电子邮件(Programmatically encrypt Ou

2019-07-29 06:14发布

我使用C#与Outlook对象模型(赎回不是我的选择,由于许可),我有困难,在发送之前编程加密的电子邮件。

我可以成功地得到这理应代表加密按钮的CommandBarButton的参考(根据网上的例子编号718),但我不能以编程方式抑制它。 我试图同时使用CommandBarButton的execute()方法和使用的SendKeys(不知道的SendKeys是有效的,即使在这种情况下)。 所有的Debug.WriteLine报表显示,该按钮在msoButtonUp状态。

我一直在玩这个了天,似乎无法得到它的工作。 任何意见,将不胜感激!

Outlook.MailItem emailToSend;
...
Microsoft.Office.Core.CommandBarButton cbb = null;
cbb =(CommandBarButton)emailToSend.GetInspector.CommandBars["Standard"].FindControl(Type.Missing, 718, Type.Missing, true, false);

if (cbb != null) {
  //it is not null in debugger    
  if (cbb.Enabled) { 
  //make sure digital signature is on
    cbb.Visible = true;
    Debug.WriteLine("State was: " + cbb.State.ToString()); //all debug calls return msoButtonUp
    cbb.SetFocus();
    SendKeys.SendWait("{ENTER}");
    Debug.WriteLine("State was: " + cbb.State.ToString());
    SendKeys.SendWait("~");
    Debug.WriteLine("State was: " + cbb.State.ToString());
    cbb.Execute();
    Debug.WriteLine("State was: " + cbb.State.ToString());
  }
}              

Answer 1:

实际上,有一个更好的方法以编程方式加密,签名,加密+号,或确保两者都不是。 你可以做到这一点,而不必显示邮件项目。 下面的文章说明了如何使用邮件项目的性质:

http://support.microsoft.com/kb/2636465?wa=wsignin1.0

例如,在C#中,如果MITEM是您的邮件项,然后将下面的代码将关闭签名和加密:

mItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 0);


Answer 2:

理解了它的试验和错误。 主要的问题似乎是,我用的是督察已显示的MailItem之前。 添加呼叫显示在开始解决它。 任何有兴趣,这里是为我工作的代码:

private static void addOutlookEncryption(ref Outlook.MailItem mItem) {
        CommandBarButton encryptBtn;
        mItem.Display(false);
        encryptBtn = mItem.GetInspector.CommandBars.FindControl(MsoControlType.msoControlButton, 718, Type.Missing, Type.Missing) as CommandBarButton;
        if (encryptBtn == null) {
            //if it's null, then add the encryption button
            encryptBtn = (CommandBarButton)mItem.GetInspector.CommandBars["Standard"].Controls.Add(Type.Missing, 718, Type.Missing, Type.Missing, true);
        }
        if (encryptBtn.Enabled) {
            if (encryptBtn.State == MsoButtonState.msoButtonUp) {
                encryptBtn.Execute();
            }
        }
        mItem.Close(Outlook.OlInspectorClose.olDiscard);
    }


文章来源: Programmatically encrypt Outlook email using Inspector