2015-08-15 177 views
0

我目前正在與該API的Outlook玩弄於2013年在C#中,是在創造一個聯絡小組(DataList控件)時,我遇到了一個奇怪的問題的過程。展望2013 API添加聯繫人到編程方式創建聯繫人組

我能夠創建一個聯絡小組沒關係使用下面的代碼,創建後然而,似乎在接觸組中沒有接觸。

然而,創建經檢查時的組和添加觸點(的過濾器必須有一個電子郵件地址),我可以看到觸點被存儲在它被保存之前的觸頭組的顯示。

 Outlook.DistListItem distList = Application.CreateItem(Outlook.OlItemType.olDistributionListItem) as Outlook.DistListItem; 
     distList.Subject = "TEST GROUP"; 
     // grab all addresses such that primary email is not an empty string 
     string filter = "[Email1Address] <> ''"; 
     // grab the table of users 
     Outlook.Table table = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).GetTable(filter, Outlook.OlTableContents.olUserItems); 
     // addingin email address so table must have column to represent this 
     table.Columns.Add("Email1Address"); 
     while (!table.EndOfTable) 
     { 
      Outlook.Row nextRow = table.GetNextRow(); 
      if (nextRow["Email1Address"] == null) 
      { 
       // no more addresses left to process. 
       break; 
      } 
      else 
      { 
       // create a recipient based upon information in our table 
       Outlook.Recipient recipient = Application.Session.CreateRecipient(nextRow["Email1Address"].ToString()); 
       // ensure recipient is valid by checking our address book for resolution 
       recipient.Resolve(); 
       MessageBox.Show(recipient.ToString() + "\nEOT: " + table.EndOfTable); 
       distList.AddMember(recipient); 
      } 
     } 
     // name the list? 
     distList.DLName = "Testing addin"; 
     // save the list 
     distList.Save(); 

當嘗試發送電子郵件到這個聯絡小組,我提示以下錯誤消息:

聯絡小組(一個或多個)此消息被髮送到必須包含至少一個收件人。

+0

確定Recipient.Resolve()返回true? –

+0

是的,因爲我直接從我的聯繫人把他們的書,我曾以爲他們會正確解析,但是我查了所有條目,每一個被返回true。 – Healsgood

回答

0

我沒有問題,從OutlookSpy運行以下腳本(點擊腳本按鈕上OutlookSpy絲帶,將腳本粘貼,單擊運行):

set DL = Application.Session.GetDefaultFolder(olFolderContacts).Items.Add(olDistributionListItem) 
set Recip = Application.Session.CreateRecipient("[email protected]") 
Recip.Resolve 
DL.AddMember(Recip) 
DL.DLName = "Testing addin" 
DL.Save 
相關問題