2012-05-03 25 views
2

私はOutlook Object Modelで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()); 
    } 
}    
+0

いくつかの追加情報:私がcbb.State = MsoButtonState.msoButtonDownを試してみると、私はHRESULT E_FAILでランタイムCOM例外を取得します。 –

答えて

1

試行錯誤でそれを示します。主な問題は、MailItemを表示する前にInspectorを使用していたようです。最初にDisplayへの呼び出しを追加すると、それが解決されました。興味のある人のために、ここに私のために働いていたコードは次のとおりです。

プログラムで、暗号化符号、暗号化+記号、またはどちらを確保するための良い方法は実際にあります
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); 
    } 
2

。そして、あなたはメールアイテムを表示することなくそれを行うことができます。

:mItemがある場合は、C#で、お使いのメールアイテムを例えば

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

、その後、次のコードは、署名と暗号化をオフにします:メールアイテムのプロパティを使用してどのように、次の資料を示してい

mItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 0); 
関連する問題