Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get User's Email Address Part II (any)

    I'm reporting some success in getting the currently logged
    in user's email address -- the SMTP address -- from an
    Exchange server via CDO. With core gleanings from
    CDOLive.com here's a tweakable function. I still want to try
    the LDAP solution to see what that does. The key to this is
    the PR_EMS_AB_PROXY_ADDRESSES constant value
    which references all the Exchange Email address names
    for the current user. Of note is the simple technique for
    returning the "Reply address" as the prefered SMTP
    address when the user has more than one SMTP "alias".
    The "reply address" in Exchange is the one with SMTP in
    uppercase. Any other SMTP address has that prefix in
    lower case.

    The MAPI objects for this function are all declared in the module declaration section and not reproduced here.

    Function CurrentUserEmailAddress() As String
    'The e-mail addresses (also known as 'Proxy Addresses') are stored in a multivalued MAPI property. Here is how to read this multivalued property:
    ' MAPI property tag for e-mail addresses
    Const PR_EMS_AB_PROXY_ADDRESSES = &H800F101E

    ' Array for e-mail addresses
    Dim strAddresses
    Dim i As Integer

    ' Get current user object
    Set objSession = CreateObject("MAPI.Session")
    On Error Resume Next
    objSession.Logon ShowDialog:=False, NewSession:=False

    Select Case Err.Number
    Case -2147221231
    On Error GoTo 0
    On Error Resume Next
    objSession.Logon ShowDialog:=False, NewSession:=True ', profileinfo:="MSXServer" & vbLf & Environ("UserName")
    If Err.Number <> 0 Then
    'MsgBox "Error trying to start Outlook"
    CurrentUserEmailAddress = "admin@domain.name"
    Exit Function
    End If
    '[Collaboration Data Objects - [MAPI_E_LOGON_FAILED(80040111)]]
    'Set the value to a known good address so the email can at least be sent

    End Select

    Set objAddressEntry = objSession.CurrentUser

    ' Get the fields collection of the address entry
    Set objFields = objAddressEntry.Fields

    ' Pull out proxy addresses
    Set objMailAddresses = objFields.Item(PR_EMS_AB_PROXY_ADDRESSES)
    If Not objMailAddresses Is Nothing Then
    ' Add the addresses to an array
    strAddresses = objMailAddresses.Value
    For i = LBound(strAddresses) To UBound(strAddresses)
    If Left$(strAddresses(i), 4) = "SMTP" Then
    MsgBox i & ": SMTP E-mail address: " & strAddresses(i)
    Exit For
    End If
    Next
    End If
    CurrentUserEmailAddress = strAddresses(i)
    objSession.Logoff
    Set objMailAddresses = Nothing
    Set objFields = Nothing
    Set objAddressEntry = Nothing
    Set objSession = Nothing
    End Function
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  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 User's Email Address Part II (any)

    Which reference(s) are you setting, or, because you are using an undeclared variable, is it using run-time binding?
    Attached Images Attached Images

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get User's Email Address Part II (any)

    The top one in your graphic CDO 1.21
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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