Announcement

Collapse
No announcement yet.

Finding the smtp email by exchange server id

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding the smtp email by exchange server id

    Using my Outlook 2007 VBA i can do this but several of our colleagues use v2003.
    Is there a way to enum exchange server entries for a specific user?
    I currently have like:

    "/o=COMPANYNAMEHERE/ou=first administrative group/cn=Recipients/cn=EdwinK"

    Like using WMI or so?
    I found some topics but i did not understand them at this time.
    This maybe be processed via VBA as PowerBASIC or c#
    hellobasic

  • #2
    That the canonical name of your user object in AD... Just a few lines of script in powershell or vbscript could get you the mail attribute (or proxyaddresses which you could parse out the primary SMTP address and any others you may want to see). And just a one liner with console utils like dsget, adfind, etc.

    But I have yet to see much related to Active Directory here.

    In VS you have many ways to access AD... you could use ADSI (Active DS Type Library), Active Directory Services OleDB Provider (ADsDSOObject), or .NET DirectoryService classes with very little effort. You should be able to use those same interfaces, but I don't believe anyone has put a nice wrapper around them for PB. So I suspect it would be some initial effort in PB.
    Last edited by Frank Buzin; 24 Mar 2009, 01:41 AM. Reason: Clarify

    Comment


    • #3
      Here's a short excerpt of what I use when accessing ActiveDirectory
      (For this example, I query AD (field cn = common name) with the UserID of the logged-in User.)

      This one
      "/o=COMPANYNAMEHERE/ou=first administrative group/cn=Recipients/cn=EdwinK"
      seems to be "legacyExchangeDN" in AD.
      Maybe it helps.
      Code:
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "Win32API.inc"
      DECLARE FUNCTION SafeArrayGetElement LIB "OLEAUT32.DLL" ALIAS "SafeArrayGetElement" (BYVAL psa AS DWORD, BYVAL rgIndices AS DWORD, BYVAL pv AS DWORD) AS DWORD
      '-------------------------------------
      '      Globale Deklarationen
      '-------------------------------------
           GLOBAL Fld_Namen()        AS STRING
           GLOBAL Anz_Fld            AS LONG
           GLOBAL QueryString        AS STRING
           GLOBAL GefUser ()         AS STRING
           GLOBAL Feld               AS VARIANT
      ''AD-Variablen
           GLOBAL oConnection         AS DISPATCH
           GLOBAL RS                  AS DISPATCH
           GLOBAL vProvider           AS VARIANT
           GLOBAL vOpenString         AS VARIANT
           GLOBAL vConnection         AS VARIANT
           GLOBAL vEOF                AS VARIANT
           GLOBAL vCmdString          AS VARIANT
           GLOBAL pv                  AS DWORD PTR 'Variant array (Public Delegates)
      FUNCTION PBMAIN () AS LONG
            LOCAL antw                AS STRING
            DIM Fld_Namen   (1 TO 30) AS STRING
            LOCAL i                   AS LONG
            LOCAL z                   AS LONG
            LOCAL Ausgabe             AS STRING
            z = 0
          ''initialize fields and redim array
          CALL Felder
          DIM GefUser (1 TO Anz_Fld)
          CALL AD_Open
          vCmdString = QueryString & "cn='" & TRIM$(getbenutzer) & "*'"
          OBJECT CALL rs.open(vCmdString, vConnection)
          OBJECT GET Rs.EOF TO vEOF
          DO WHILE VARIANT#(vEOF) = 0
              FOR i = 1 TO Anz_Fld
                  Feld = Fld_Namen (i)
                  OBJECT GET Rs.Fields.Item(Feld).Value TO Feld
                  '*****************************************
                  ' If variant array, then convert
                  '*****************************************
                  ' Get public delegate
                  IF VARIANTVT(Feld) = 8204 THEN
                      SafeArrayGetElement(@pv[2], BYVAL VARPTR(z), BYVAL VARPTR(Feld))
                      Feld = VARIANT$(Feld)
                  END IF
                  GefUser(i) = VARIANT$(Feld)
              NEXT i
              OBJECT CALL Rs.movenext
              OBJECT GET Rs.EOF TO vEOF
          LOOP
          CALL AD_Close
          FOR i = 1 TO Anz_Fld
              Ausgabe = Ausgabe & fld_Namen(i) & ": " & GefUser(i) & $CRLF
          NEXT i
          MSGBOX Ausgabe
      END FUNCTION
      '--------------------------------
      SUB Felder
          pv      = VARPTR(Feld)
          'QueryString = "SELECT cn, displayName, title, telephoneNumber, ipPhone, department, physicalDeliveryOfficeName, mobile, mail, facsimileTelephoneNumber, publicDelegates "
          Fld_Namen(01) = "cn"
          Fld_Namen(02) = "displayName"
          Fld_Namen(03) = "title"
          Fld_Namen(04) = "telephoneNumber"
          Fld_Namen(05) = "ipPhone"
          Fld_Namen(06) = "department"
          Fld_Namen(07) = "physicaldeliveryofficename"
          Fld_Namen(08) = "mobile"
          Fld_Namen(09) = "mail"
          Fld_Namen(10) = "facsimileTelephoneNumber"
          Fld_Namen(11) = "language"
          Fld_Namen(12) = "publicDelegates"
          Fld_Namen(13) = "legacyExchangeDN"
          Anz_Fld       = 13
          QueryString = "SELECT " + _
              Fld_Namen(01) + ", " + _
              Fld_Namen(02) + ", " + _
              Fld_Namen(03) + ", " + _
              Fld_Namen(04) + ", " + _
              Fld_Namen(05) + ", " + _
              Fld_Namen(06) + ", " + _
              Fld_Namen(07) + ", " + _
              Fld_Namen(08) + ", " + _
              Fld_Namen(09) + ", " + _
              Fld_Namen(10) + ", " + _
              Fld_Namen(11) + ", " + _
              Fld_Namen(12) + ", " + _
              Fld_Namen(13) + "  " + _
              "FROM 'LDAP://dc=mobi,dc=mobicorp,dc=ch' WHERE objectCategory='person' AND "
      END SUB
      '-----------------------------------
      '      Helpers
      '-----------------------------------
      SUB AD_Open
          '''Open AD connection
          vProvider = "ADSDSOObject"
          vOpenString = "Active Directory Provider"
          SET oConnection = NEW DISPATCH IN "ADODB.Connection"
          OBJECT LET oConnection.Provider = vProvider
          OBJECT CALL oConnection.Open(vOpenString)
          SET vConnection = oConnection
          SET rs = NEW DISPATCH IN "ADODB.Recordset"
      END SUB
      '-----------------------------------
      SUB AD_Close
          '''Close AD connection
          OBJECT CALL Rs.Close
          SET oConnection = NOTHING
          SET rs = NOTHING
      END SUB
      '-----------------------------------
      FUNCTION GetBenutzer() AS STRING
          LOCAL lpBuffer     AS ASCIIZ*256
          LOCAL nSize        AS DWORD
          nSize=256
          GetUserName lpBuffer, nSize
          GetBenutzer = TRIM$(lpBuffer)
      END FUNCTION
      '-----------------------------------

      Comment


      • #4
        Tried but failed, maybe later..
        We use a translation table in out db at this time.
        not 100% but not so bad.
        hellobasic

        Comment


        • #5
          You did modify this line, I reckon?

          Code:
           "FROM 'LDAP://dc=mobi,dc=mobicorp,dc=ch' WHERE objectCategory='person' AND "

          Comment


          • #6
            Yes i tried several scenario's, believe me.
            I do have connection but 'table' not found.

            Can you make suggestions how to modfiy the LDAP line for my situation?

            In Outlook's accountsettings >Email tab i doubleclick my name (email actually) and get the servername, for example:
            myserver1.thecompany.nl

            Username "Edwin Knoppert"

            Should this be part of the LDAP connection?
            hellobasic

            Comment


            • #7
              What's the exact error message?

              [quote=Edwin Knoppert;312441]Can you make suggestions how to modfiy the LDAP line for my situation?

              this should be something along the line of
              Code:
              "FROM 'LDAP://dc=myserver1,dc=thecompany,dc=nl' WHERE objectCategory='person' AND "
              Originally posted by Edwin Knoppert View Post
              In Outlook's accountsettings >Email tab i doubleclick my name (email actually) and get the servername, for example:
              myserver1.thecompany.nl
              That's strange, because in Outlook, in connection with an exchange server, there shouldn't be an "account setting" but an entry called "services"

              Comment


              • #8
                Markus' code works here... cool. From a previous search I didn't find too many hits on AD... few had any code, so I didn't think we had many here interested in it.

                Edwin, just for a test... if you pull down adfind from joeware.net and run:

                adfind -default -f "&(sAMAccountType=805306368)(legacyExchangeDN=/o=COMPANYNAMEHERE/ou=first administrative group/cn=Recipients/cn=EdwinK)" mail

                do you get what you were looking for?

                Comment


                • #9
                  Frank, thanks for your feedback.

                  Comment

                  Working...
                  X