2012-05-22 56 views
0

我一直在試圖找出一種方法來找出郵件已發送到的郵件地址。考慮以下幾點:從mailItem的收件人中獲取mailaddress

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String) 
    Dim mai As MailItem 
    Dim intInitial As Integer 
    Dim intFinal As Integer 
    Dim strEntryId As String 
    Dim intLength As Integer 

    intInitial = 1 
    intLength = Len(EntryIDCollection) 
    intFinal = InStr(intInitial, EntryIDCollection, ",") 
    Do While intFinal <> 0 
     strEntryId = Strings.Mid(EntryIDCollection, intInitial, (intFinal - intInitial)) 
     Set mai = Application.Session.GetItemFromID(strEntryId) 
     intInitial = intFinal + 1 
     intFinal = InStr(intInitial, EntryIDCollection, ",") 
    Loop 
    strEntryId = Strings.Mid(EntryIDCollection, intInitial, (intLength - intInitial) + 1) 
    MsgBox strEntryId 
    Set mai = Application.Session.GetItemFromID(strEntryId) 
    For Each Recipient In mai.Recipients 
     MsgBox Recipient 
    Next 
End sub 

在那些msgBoxes我得到的「好名」,如「李四」 - 但我想獲得的郵件地址,「[email protected]」。

我該如何做到這一點?

謝謝!

回答

6

我認爲這是Outlook 2007+。你有沒有試過Address Property

For Each Recipient In mai.Recipients 
    MsgBox Recipient.Address 
Next Recipient 

這應該打印每個收件人的電子郵件地址。

+0

這是一個正確的假設。我正在使用Outlook 2010.我會馬上測試。謝謝! – Zyberzero

相關問題