Question

I been trying to find out a way to find out wich mail adresses 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?

Thanks!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top