Per­haps you want to send a gen­er­ated E-Mail from a script and you need to con­vert the cur­rent user infor­ma­tion into his E-Mail address stored in the AD. This is quite a sim­ple job with a .VBS script:

1
2
3
4
5
Set objNet­work = CreateObject(“Wscript.Network”)
strUser = objNetwork.UserName
str­Do­main = objNetwork.UserDomain
mailAdr = GetEmail(strUser, str­Do­main)
wscript.echo mailAdr

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Func­tion GetEmail(strAccountName, str­Do­main­Name)
Dim adoLDAP­Con, _
adoLDAPRS, _
strL­DAP

Set adoLDAP­Con = CreateObject(“ADODB.Connection”)
adoLDAPCon.Provider = “ADs­D­SOOb­ject“
adoLDAPCon.Open “ADSI
strL­DAP = “‘LDAP://” & str­Do­main­Name & “‘“
Set adoLDAPRS = adoLDAPCon.Execute(“select mail from ” §
& strL­DAP &WHERE object­Class = ‘user’”& §
” And samAc­count­Name = ’” & strAc­count­Name & “‘”)
With adoLDAPRS
If Not .EOF Then
GetEmail = .Fields(“mail”)
Else
GetEmail = ““
End If
End With
adoLDAPRS.Close
Set adoLDAPRS = Noth­ing
Set adoLDAP­Con = Noth­ing
End Function

Quite sim­ple huh? I use this script as a fron­tend for my com­mand line mailer mms.

Btw. I found this code in a news­group, but I for­get where it was..