2014-10-31 86 views
0

我想通過自定義發送按鈕的Application_ItemSend事件來使用C#創建Outlook Addin。Outlook.MailItem - 無法從Outlook中獲取,CC&BCC

我需要發送電子郵件之前的所有電子郵件詳細信息。

當我運行下面的代碼@我的家我通過把一些個人電子郵件ID它的工作得到適當的結果。

但是當我在office outlook機器上運行這個類似的代碼時,我得到了名字。

由於默認情況下,outlook的檢查名稱代碼已啓用,因此會返回名和姓。

我正在使用Outlook 2010 @這兩個地方。 Office Outlook被映射到辦公室活動目錄。我的家庭前景未被映射。任何人都可以提供一個通用的解決方案,它將給我所有使用的電子郵件地址(cc,密碼爲&),而不管活動目錄是否映射。

private void ThisAddIn_Startup(object sender, System.EventArgs e)  { 
      Application.ItemSend += new   Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend); 
} 

void Application_ItemSend(object Item, ref bool Cancel)  { 
Outlook.MailItem mail = Item as Outlook.MailItem;    
Outlook.Inspector inspector = Item as Outlook.Inspector; 

System.Windows.Forms.MessageBox.Show(mail.CC); 
System.Windows.Forms.MessageBox.Show(mail.BCC); 

} 

回答

0

爲了/ CC/BCC特性(對應於PR_DISPLAY_TO/CC/BCC在MAPI)由存儲提供當物品被保存(MailItem.Save)更新。您還可以使用MailItem.Recipeints集合訪問所有收件人。

+0

所以我應該保存的MailItem第一個拿到的細節?你想說什麼?但我面臨的問題是我得到的名稱,而不是電子郵件ID ...像(sameer k),而不是[email protected] ...但在我家安裝它的工作正常...作爲展望映射到家裏的gmail ... – 2014-10-31 16:05:21

+0

是的,你需要保存該消息才能夠讀取To/CC/BCC屬性。如果您需要這些地址,請使用我的第二個建議,並通過MailItem.Recipients集合進行循環。對於每個收件人對象,請閱讀其地址,名稱,類型屬性。 – 2014-10-31 17:35:56

+0

嗨..我嘗試使用到/ CC /密件抄送沒有保存mailItem,但從收件人Object.But迭代得到的結果像一個ldap查詢.../O = SOMEVALUE/OU = SOMEVALUE/cn = Recipients/cn = SOMEVALUE in地址屬性....有沒有其他的方式,我可以得到emailaddress ..? – 2014-11-03 10:49:43

0

也許已經晚了,但有人可以檢查此代碼(它的工作對我來說)

private string[] GetCCBCCFromEmail(Outlook.MailItem email) 
    { 
     string[] ccBCC = new string[] { "", "" };//cc y bcc 
     Outlook.Recipients recipients = email.Recipients; 

     foreach (Outlook.Recipient item in recipients) 
     { 
      switch (item.Type) 
      { 

       case (int)Outlook.OlMailRecipientType.olCC:       
        ccBCC[0] += GetEmail(item.AddressEntry) + ";"; 
        break; 
       case (int)Outlook.OlMailRecipientType.olBCC: 
        ccBCC[1] += GetEmail(item.AddressEntry) + ";"; 
        break; 
      } 
     } 
     return ccBCC; 
    } 
    private string GetEmail(Outlook.AddressEntry address) 
    { 
     string addressStr = ""; 

     if (address.AddressEntryUserType == 
       Outlook.OlAddressEntryUserType. 
       olExchangeUserAddressEntry 
       || address.AddressEntryUserType == 
       Outlook.OlAddressEntryUserType. 
       olExchangeRemoteUserAddressEntry) 
     { 
      //Use the ExchangeUser object PrimarySMTPAddress 
      Outlook.ExchangeUser exchUser = 
       address.GetExchangeUser(); 
      if (exchUser != null) 
      { 
       addressStr = exchUser.PrimarySmtpAddress; 
      } 
     } 
     //Get the address from externals 
     if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType. 
      olSmtpAddressEntry) 
     { 
      addressStr = address.Address; 
     } 

     return addressStr; 
    } 

希望它可以幫助