I'm using C# with Outlook Object Model (Redemption is not an option for me due to licensing) and I'm having difficulty programmatically encrypting an email message before sending it.
I can successfully get a reference to the CommandBarButton which supposedly represents the Encrypt button (Id 718 according to online examples), but I cannot programmatically depress it. I tried using both the CommandBarButton Execute() method and using SendKeys (not sure if sendkeys is even valid in this context). All debug.writeline statements show that the button is in the msoButtonUp state.
I've been playing with this for days and cannot seem to get it working. Any advice would be much appreciated!
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());
}
}