Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get email address from name (VBA (Off2003))

    I want to automatically resolve a name or ID to out Exchange directory and then get the email-address (I need that to build a DL).

    The function below, takes a string and resolves it against the directory. I'm missing the conversion to the email address...

    Function MailResolve(Inpt As String) As String
    Dim objSession As MAPI.Session
    Dim objNewMessage As MAPI.Message
    Dim objNewRecip
    '
    MailResolve = Inpt
    On Error GoTo NoMAPI
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon ShowDialog:=False, NewSession:=False
    ' Create new message
    Set objNewMessage = objSession.Outbox.Messages.Add
    Set objNewRecip = objNewMessage.Recipients.Add
    objNewRecip.Name = Inpt
    ' Resolve address against the Exchange Directory
    objNewRecip.Resolve
    '
    MailResolve = objNewMessage.Recipients(1)
    ' Update and delete message
    objNewMessage.Update
    objNewMessage.Delete
    '
    objSession.Logoff
    Set objSession = Nothing
    '
    On Error GoTo 0
    Exit Function
    NoMAPI:
    MsgBox "Cannot initiate Mail-system", vbCritical + vbOKCancel, "MailResolve"
    End Function

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Get email address from name (VBA (Off2003))

    Let me guess, you get one of those long Exchange internal addresses... I don't see a handy property in the object model to access the SMTP address, if that's what you are looking for. There probably is a trick, but it might involve querying Active Directory rather than working with the Recipient object.

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get email address from name (VBA (Off2003))

    Don't know... we have sort of UserIDs here. Using the code, this is recognized and then transformed to my full name by the code (no more, just my name as string). This means to me that my entry is found and my name is retrieved from there. In that same 'entry', somewhere there is my outside email address too. I (think) I need that to build a DL (although the DL is for internal use only so maybe I don't need the external email address but then I don't know what to 'feed' info my DL-creator to make it work...). I'm confused

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get email address from name (VBA (Off2003))

    Does this do what you want?

    MailResolve = objNewMessage.Recipients(1).AddressEntry.Address

  5. #5
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get email address from name (VBA (Off2003))

    Nope, comes back with something like "/o=xxx/ou=yyy/cn=Recipients/cn=myID"

  6. #6
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get email address from name (VBA (Off2003))

    Still the thought process helped me... I played some more and found that if I use my userID, it will work to build the DL afterall. So I guess it's fixed now. Thanks for the help & tips.

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Get email address from name (VBA (Off2003))

    The SMTP name isn't exposed, even though you can see it in GAL Properties for the address. Seems like your problem is resolved, but FWIW there's a loop in the middle of the <post#=569,146>post 569,146</post#> code, to which you would have to add the company domain.
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •