0

I been trying to find out a way to find out which mail addresses a mail has been sent to. Consider the following:

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

In those msgBoxes I get the "nice name", Like "John Doe" - but I want to get the mail address, "john.doe@gmail.com".

How can I achieve this?

4

1 回答 1

6

I assume this is Outlook 2007+. Have you tried the Address Property?

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

This should print the email address of each recipient.

于 2012-05-24T00:16:58.340 回答