【发布时间】:2014-12-19 01:51:19
【问题描述】:
我将 C# 与 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 异常。
标签: c# outlook office-interop outlook-addin office-automation