2013-10-18 46 views
0

我使用以下代碼來獲取要發送的每個郵件收件人的ContactInfo(在Outlook2010中)。代碼工作,但只適用於少數聯繫人,儘管所有聯繫人都存儲在我的adressbook中。對於一些最後一行(GetContact)沒有提供。爲什麼?使用Redemption(Outlook 2010)獲取郵件的每個收件人的ContactInfo

「創建RDO會話 昏暗會話 設置會話=的CreateObject( 」Redemption.RDOSession「)

Set session.MAPIOBJECT = Application.session.MAPIOBJECT 

' Get current email 

ActiveInspector.CurrentItem.Save ' Necessary to get current status 
Dim mail 
Set mail = session.GetMessageFromID(ActiveInspector.CurrentItem.EntryID) 

' Create salutation line 
Dim salutationLine As String 
salutationLine = "" 

For Each Recipient In mail.Recipients 
    ' Skip CC and BCC addresses 
    If (Recipient.Type <> olTo) Then GoTo NextRecipient 

    ' Assume standard salutation and use complete name as first name 
    Dim salutationType As String 
    salutationType = "" 
    Dim firstName As String 
    Dim lastName As String 
    Dim recipientName As String 

    recipientName = IIf(Recipient.Name <> "", Recipient.Name, Recipient.Address) 
    lastName = "" 

    If InStr(1, recipientName, " ") > 0 Then 
     firstName = Split(recipientName, " ")(0) 
     lastName = Split(recipientName, " ")(1) 
    End If 
    Dim addressEntry 
    Set addressEntry = Recipient.addressEntry 
    If (Not addressEntry Is Nothing) Then 
     ' If we have qualified name information: extract first and last name 
     If (addressEntry.firstName <> "") Then firstName = addressEntry.firstName 
     If (addressEntry.lastName <> "") Then lastName = addressEntry.lastName 

     Dim contactInfo 
     Set contactInfo = addressEntry.GetContact() 



     If (Not contactInfo Is Nothing) Then 

回答

1

GetContact在Outlook對象模型和贖回依賴於OAB類型的條目ID爲。在傳入郵件中,所有SMTP收件人都有一次性條目標識(它不指向任何現有的地址簿對象並在其中嵌入名稱,地址和地址類型)。

通常,您需要提取收件人地址,然後根據email1,email2或email3值在聯繫人文件夾中搜索匹配的聯繫人。

+0

對不起,我上面的代碼試圖在新的郵件上發送這個郵件。因此,我們不是在討論傳入的電子郵件,而是在談論傳出的電子郵件 – user668338

+0

如果您手動輸入地址或使用了自動填充,而不是點擊「收件人」按鈕並選擇其中一個聯繫人,則仍然可以獲得一次性條目ID。 –

相關問題