2014-12-05 101 views
0

我想開發電子郵件跟蹤插件的Outlook中的c#,我能夠創建插件,但不知道如何跟蹤從我的Outlook使用C#發送的電子郵件,請分享任何引用博客或代碼。 我創建簡單的Hello World插件前景在c#中開發電子郵件跟蹤插件的Outlook#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml.Linq; 
using Outlook = Microsoft.Office.Interop.Outlook; 
using Office = Microsoft.Office.Core; 


namespace MyAddin 
{ 
public partial class ThisAddIn 
{ 
    private Office.CommandBar _objMenuBar; 
    private Office.CommandBarPopup _objNewMenuBar; 
    //private Outlook.Inspector Inspectors; 
    private Office.CommandBarButton _objButton; 
    private string menuTag = "MyMenu"; 
    Outlook.Inspectors inspectors; 
    private void ThisAddIn_Startup(object sender, System.EventArgs e) 
    { 
     this.MyMenuBar(); 
     //Inspectors = this.Application.Inspectors; 
     inspectors = this.Application.Inspectors; 
     inspectors.NewInspector += 
     new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); 

    } 

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e) 
    { 
    } 

    void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) 
    { 
     Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem; 
     if (mailItem != null) 
     { 
      if (mailItem.EntryID == null) 
      { 
       mailItem.Subject = "This text was added by using code"; 
       mailItem.Body = "This text was added by using code"; 
      } 

     } 
    } 

    private void MyMenuBar() 
    { 
     this.ErsMyMenuBar(); 

     try 
     { 
      _objMenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; 
      _objNewMenuBar = (Office.CommandBarPopup) 
          _objMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup 
                , missing 
                , missing 
                , missing 
                , false); 

      if (_objNewMenuBar != null) 
      { 
       _objNewMenuBar.Caption = "my Plugin"; 
       _objNewMenuBar.Tag = menuTag; 
       _objButton = (Office.CommandBarButton)_objNewMenuBar.Controls. 
       Add(Office.MsoControlType.msoControlButton, missing, 
        missing, 1, true); 
       _objButton.Style = Office.MsoButtonStyle. 
        msoButtonIconAndCaption; 
       _objButton.Caption = "my Plugin"; 
       //Icon 
       _objButton.FaceId = 500; 
       _objButton.Tag = "ItemTag"; 
       //EventHandler 
       _objButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(_objButton_Click); 
       _objNewMenuBar.Visible = true; 
      } 
     } 
     catch (System.Exception ex) 
     { 
      System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString() 
               , "Error Message"); 
     } 

    } 


    #region VSTO generated code 
    private void InternalStartup() 
    { 
     this.Startup += new System.EventHandler(ThisAddIn_Startup); 
     this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 
    } 
    #endregion 

    #region "Event Handler" 
    #region "Menu Button" 

    private void _objButton_Click(Office.CommandBarButton ctrl, ref bool cancel) 
    { 
     try 
     { 
      System.Windows.Forms.MessageBox.Show("Hello World"); 
     } 
     catch (System.Exception ex) 
     { 
      System.Windows.Forms.MessageBox.Show("Error " + ex.Message.ToString()); 
     } 
    } 

    #endregion 

    #region "Remove Existing" 

    private void ErsMyMenuBar() 
    { 
     // If the menu already exists, remove it. 
     try 
     { 
      Office.CommandBarPopup _objIsMenueExist = (Office.CommandBarPopup) 
       this.Application.ActiveExplorer().CommandBars.ActiveMenuBar. 
       FindControl(Office.MsoControlType.msoControlPopup 
          , missing 
          , menuTag 
          , true 
          , true); 

      if (_objIsMenueExist != null) 
      { 
       _objIsMenueExist.Delete(true); 
      } 
     } 
     catch (System.Exception ex) 
     { 
     System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString(), "Error Message"); 
     } 
    } 
    #endregion 
    #endregion 
} 

}

回答

0

我看到你使用的命令欄的代碼。從Office 2007開始使用新的UI。從Office 2010開始,不推薦使用命令欄。您需要使用Fluent UI(又名功能區UI)。您可以在下面的系列文章閱讀更多有關新UI:

有追蹤郵件不同的方式:

  1. 添加一個自定義屬性。這不是最好的辦法,因爲財產可以消失。
  2. 使用Outlook項目的對話*(* Id + *索引)屬性。 Outlook使用這些屬性來分組對話中的相關項目。
  3. 顯式將您的ID添加到主題行。

這是給你這辦法是選擇......

+0

可以請你告訴我怎麼可以跟蹤電子郵件被打開與否。我能夠獲得插件。 – 2014-12-09 11:45:02

+0

您是否試圖處理[NewInspector](http://msdn.microsoft.com/en-us/library/office/ff867841(v = office.15).aspx)和[Activate](http:// msdn .microsoft.com/en-us/library/office/ff865363(v = office.15).aspx)events? – 2014-12-09 19:28:55