我使用C#與Outlook對象模型(由於授權,兌換不是我的選項),而且我在發送郵件之前編程加密電子郵件時遇到困難。使用Inspector以編程方式加密Outlook電子郵件
我可以成功地獲得對CommandBarButton的引用,該引用應該表示加密按鈕(根據在線示例的Id 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());
}
}
一些額外的信息:當我嘗試cbb.State = MsoButtonState.msoButtonDown;我用HRESULT E_FAIL得到了一個運行時COM異常。 –