Reading windows user's email address

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Reading windows user's email address

    Hi

    Outlook 2003 connected with exchange server.

    A user is logged in to the client pc. Is it possible to programmaticall y get
    the user's email address that is set on the 'Email Addresses' tab of the
    exchange server?

    Thanks

    Regards



  • bwspell@cox.net

    #2
    Re: Reading windows user's email address

    On May 30, 1:28 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
    Hi
    >
    Outlook 2003 connected with exchange server.
    >
    A user is logged in to the client pc. Is it possible to programmaticall y get
    the user's email address that is set on the 'Email Addresses' tab of the
    exchange server?
    >
    Thanks
    >
    Regards
    Add a reference for
    Imports System.Net.Mail

    Then:
    Dim mail As New MailMessage()
    mail.To = "me@mycompany.c om"
    mail.From = "you@yourcompan y.com"
    mail.Subject = "this is a test email."
    mail.Body = "this is my test email body."
    Dim attachment As New MailAttachment( Server.MapPath( "test.txt") )
    'create the attachment
    mail.Attachment s.Add(attachmen t) 'add the attachment
    SmtpMail.SmtpSe rver = "localhost" 'your real server goes here
    SmtpMail.Send(m ail)

    You can also do a search on reading the Active Directory, it was very
    helpful for me.

    regards,

    Big B

    Comment

    • bwspell@cox.net

      #3
      Re: Reading windows user's email address

      On May 30, 1:28 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
      Hi
      >
      Outlook 2003 connected with exchange server.
      >
      A user is logged in to the client pc. Is it possible to programmaticall y get
      the user's email address that is set on the 'Email Addresses' tab of the
      exchange server?
      >
      Thanks
      >
      Regards
      Here is the code for searching the Active Directory I use:

      Dim oroot As DirectoryServic es.DirectoryEnt ry = New
      DirectoryServic es.DirectoryEnt ry("LDAP://ATOMIC")
      Dim osearcher As DirectoryServic es.DirectorySea rcher = New
      DirectoryServic es.DirectorySea rcher(oroot)

      osearcher.Searc hScope = SearchScope.Sub tree
      Dim oResults As SearchResultCol lection
      Dim oResult As SearchResult


      osearcher.Filte r = "(&(objectCateg ory=user)
      (objectClass=us er)(sn=" & mLast & "))"

      osearcher.Prope rtiesToLoad.Add ("cn")

      osearcher.Prope rtiesToLoad.Add ("SAMAccountNam e") 'Users login name

      osearcher.Prope rtiesToLoad.Add ("givenName" ) 'Users first name

      osearcher.Prope rtiesToLoad.Add ("sn") 'Users last name

      osearcher.Prope rtiesToLoad.Add ("mailNickname" ) 'Users Alias

      osearcher.Prope rtiesToLoad.Add ("mail") 'Users email

      oResults = osearcher.FindA ll

      For Each oResult In oResults
      If oResult.Propert ies("sn")(0) = mLast And
      oResult.Propert ies("givenName" )(0) = mFirst Then
      If Not oResult.Propert ies("mail")(0) =
      "" Then
      mEmail = oResult.Propert ies("mail")
      (0)
      mCCHDLogin =
      oResult.Propert ies("samAccount Name")(0)
      Exit For
      End If
      End If
      Next

      Comment

      • bwspell@cox.net

        #4
        Re: Reading windows user's email address

        On May 30, 1:28 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
        Hi
        >
        Outlook 2003 connected with exchange server.
        >
        A user is logged in to the client pc. Is it possible to programmaticall y get
        the user's email address that is set on the 'Email Addresses' tab of the
        exchange server?
        >
        Thanks
        >
        Regards
        Not sure if this posted :

        Here is the code for searching the Activr Directory:

        Dim sItem As String =
        "CN=ATOMIC,CN=S ervers,CN=CCHD, CN=Sites,CN=Con figuration,DC=C CHD,DC=ORG"

        Dim oroot As DirectoryServic es.DirectoryEnt ry = New
        DirectoryServic es.DirectoryEnt ry("LDAP://ATOMIC")
        Dim osearcher As DirectoryServic es.DirectorySea rcher = New
        DirectoryServic es.DirectorySea rcher(oroot)

        osearcher.Searc hScope = SearchScope.Sub tree
        Dim oResults As SearchResultCol lection
        Dim oResult As SearchResult


        osearcher.Filte r = "(&(objectCateg ory=user)
        (objectClass=us er)(sn=" & mLast & "))"

        osearcher.Prope rtiesToLoad.Add ("cn")

        osearcher.Prope rtiesToLoad.Add ("SAMAccountNam e") 'Users login name

        osearcher.Prope rtiesToLoad.Add ("givenName" ) 'Users first name

        osearcher.Prope rtiesToLoad.Add ("sn") 'Users last name

        osearcher.Prope rtiesToLoad.Add ("mailNickname" ) 'Users Alias

        osearcher.Prope rtiesToLoad.Add ("mail") 'Users email

        oResults = osearcher.FindA ll

        'oResult.GetDir ectoryEntry().P roperties("sn") .Value
        For Each oResult In oResults
        If oResult.Propert ies("sn")(0) = mLast And
        oResult.Propert ies("givenName" )(0) = mFirst Then
        If Not oResult.Propert ies("mail")(0) =
        "" Then
        mEmail = oResult.Propert ies("mail")
        (0)
        mLogin =
        oResult.Propert ies("samAccount Name")(0)
        Exit For
        End If
        End If
        Next

        Comment

        • John

          #5
          Re: Reading windows user's email address

          Hi

          Many thanks. This is very useful.

          Regards


          <bwspell@cox.ne twrote in message
          news:c3871db0-f298-41ce-ad94-527c12cae6e9@56 g2000hsm.google groups.com...
          On May 30, 1:28 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
          Hi
          >
          Outlook 2003 connected with exchange server.
          >
          A user is logged in to the client pc. Is it possible to programmaticall y
          get
          the user's email address that is set on the 'Email Addresses' tab of the
          exchange server?
          >
          Thanks
          >
          Regards
          Not sure if this posted :

          Here is the code for searching the Activr Directory:

          Dim sItem As String =
          "CN=ATOMIC,CN=S ervers,CN=CCHD, CN=Sites,CN=Con figuration,DC=C CHD,DC=ORG"

          Dim oroot As DirectoryServic es.DirectoryEnt ry = New
          DirectoryServic es.DirectoryEnt ry("LDAP://ATOMIC")
          Dim osearcher As DirectoryServic es.DirectorySea rcher = New
          DirectoryServic es.DirectorySea rcher(oroot)

          osearcher.Searc hScope = SearchScope.Sub tree
          Dim oResults As SearchResultCol lection
          Dim oResult As SearchResult


          osearcher.Filte r = "(&(objectCateg ory=user)
          (objectClass=us er)(sn=" & mLast & "))"

          osearcher.Prope rtiesToLoad.Add ("cn")

          osearcher.Prope rtiesToLoad.Add ("SAMAccountNam e") 'Users login name

          osearcher.Prope rtiesToLoad.Add ("givenName" ) 'Users first name

          osearcher.Prope rtiesToLoad.Add ("sn") 'Users last name

          osearcher.Prope rtiesToLoad.Add ("mailNickname" ) 'Users Alias

          osearcher.Prope rtiesToLoad.Add ("mail") 'Users email

          oResults = osearcher.FindA ll

          'oResult.GetDir ectoryEntry().P roperties("sn") .Value
          For Each oResult In oResults
          If oResult.Propert ies("sn")(0) = mLast And
          oResult.Propert ies("givenName" )(0) = mFirst Then
          If Not oResult.Propert ies("mail")(0) =
          "" Then
          mEmail = oResult.Propert ies("mail")
          (0)
          mLogin =
          oResult.Propert ies("samAccount Name")(0)
          Exit For
          End If
          End If
          Next


          Comment

          Working...