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 send
Figured it out by trial and error. The main problem seemed to be that I was using the Inspector before I had displayed the MailItem. Adding the call to Display at the beginning solved it. For anyone interested, here is the code that worked for me:
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);
}