469,628 Members | 1,205 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

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 programmatically get
the user's email address that is set on the 'Email Addresses' tab of the
exchange server?

Thanks

Regards

Jun 27 '08 #1
4 1731
On May 30, 1:28*pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

Outlook 2003 connected with exchange server.

A user is logged in to the client pc. Is it possible to programmatically 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.com"
mail.From = "yo*@yourcompany.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.Attachments.Add(attachment) 'add the attachment
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

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

regards,

Big B
Jun 27 '08 #2
On May 30, 1:28*pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

Outlook 2003 connected with exchange server.

A user is logged in to the client pc. Is it possible to programmatically 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 DirectoryServices.DirectoryEntry = New
DirectoryServices.DirectoryEntry("LDAP://ATOMIC")
Dim osearcher As DirectoryServices.DirectorySearcher = New
DirectoryServices.DirectorySearcher(oroot)

osearcher.SearchScope = SearchScope.Subtree
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
osearcher.Filter = "(&(objectCategory=user)
(objectClass=user)(sn=" & mLast & "))"

osearcher.PropertiesToLoad.Add("cn")

osearcher.PropertiesToLoad.Add("SAMAccountName") 'Users login name

osearcher.PropertiesToLoad.Add("givenName") 'Users first name

osearcher.PropertiesToLoad.Add("sn") 'Users last name

osearcher.PropertiesToLoad.Add("mailNickname") 'Users Alias

osearcher.PropertiesToLoad.Add("mail") 'Users email

oResults = osearcher.FindAll

For Each oResult In oResults
If oResult.Properties("sn")(0) = mLast And
oResult.Properties("givenName")(0) = mFirst Then
If Not oResult.Properties("mail")(0) =
"" Then
mEmail = oResult.Properties("mail")
(0)
mCCHDLogin =
oResult.Properties("samAccountName")(0)
Exit For
End If
End If
Next
Jun 27 '08 #3
On May 30, 1:28*pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

Outlook 2003 connected with exchange server.

A user is logged in to the client pc. Is it possible to programmatically 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=Servers,CN=CCHD,CN=Sites,CN=Configur ation,DC=CCHD,DC=ORG"

Dim oroot As DirectoryServices.DirectoryEntry = New
DirectoryServices.DirectoryEntry("LDAP://ATOMIC")
Dim osearcher As DirectoryServices.DirectorySearcher = New
DirectoryServices.DirectorySearcher(oroot)

osearcher.SearchScope = SearchScope.Subtree
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
osearcher.Filter = "(&(objectCategory=user)
(objectClass=user)(sn=" & mLast & "))"

osearcher.PropertiesToLoad.Add("cn")

osearcher.PropertiesToLoad.Add("SAMAccountName") 'Users login name

osearcher.PropertiesToLoad.Add("givenName") 'Users first name

osearcher.PropertiesToLoad.Add("sn") 'Users last name

osearcher.PropertiesToLoad.Add("mailNickname") 'Users Alias

osearcher.PropertiesToLoad.Add("mail") 'Users email

oResults = osearcher.FindAll

'oResult.GetDirectoryEntry().Properties("sn").Valu e
For Each oResult In oResults
If oResult.Properties("sn")(0) = mLast And
oResult.Properties("givenName")(0) = mFirst Then
If Not oResult.Properties("mail")(0) =
"" Then
mEmail = oResult.Properties("mail")
(0)
mLogin =
oResult.Properties("samAccountName")(0)
Exit For
End If
End If
Next
Jun 27 '08 #4
Hi

Many thanks. This is very useful.

Regards
<bw*****@cox.netwrote in message
news:c3**********************************@56g2000h sm.googlegroups.com...
On May 30, 1:28 pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

Outlook 2003 connected with exchange server.

A user is logged in to the client pc. Is it possible to programmatically
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=Servers,CN=CCHD,CN=Sites,CN=Configur ation,DC=CCHD,DC=ORG"

Dim oroot As DirectoryServices.DirectoryEntry = New
DirectoryServices.DirectoryEntry("LDAP://ATOMIC")
Dim osearcher As DirectoryServices.DirectorySearcher = New
DirectoryServices.DirectorySearcher(oroot)

osearcher.SearchScope = SearchScope.Subtree
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
osearcher.Filter = "(&(objectCategory=user)
(objectClass=user)(sn=" & mLast & "))"

osearcher.PropertiesToLoad.Add("cn")

osearcher.PropertiesToLoad.Add("SAMAccountName") 'Users login name

osearcher.PropertiesToLoad.Add("givenName") 'Users first name

osearcher.PropertiesToLoad.Add("sn") 'Users last name

osearcher.PropertiesToLoad.Add("mailNickname") 'Users Alias

osearcher.PropertiesToLoad.Add("mail") 'Users email

oResults = osearcher.FindAll

'oResult.GetDirectoryEntry().Properties("sn").Valu e
For Each oResult In oResults
If oResult.Properties("sn")(0) = mLast And
oResult.Properties("givenName")(0) = mFirst Then
If Not oResult.Properties("mail")(0) =
"" Then
mEmail = oResult.Properties("mail")
(0)
mLogin =
oResult.Properties("samAccountName")(0)
Exit For
End If
End If
Next
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

44 posts views Thread by Viken Karaguesian | last post: by
16 posts views Thread by bloggsfred00 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.