Perhaps you want to send a generated E-Mail from a script and you need to convert the current user information into his E-Mail address stored in the AD. This is quite a simple job with a .VBS script:
1 2 3 4 5 | Set objNetwork = CreateObject(“Wscript.Network”) strUser = objNetwork.UserName strDomain = objNetwork.UserDomain mailAdr = GetEmail(strUser, strDomain) 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 | Function GetEmail(strAccountName, strDomainName) Dim adoLDAPCon, _ adoLDAPRS, _ strLDAP Set adoLDAPCon = CreateObject(“ADODB.Connection”) adoLDAPCon.Provider = “ADsDSOObject“ adoLDAPCon.Open “ADSI“ strLDAP = “‘LDAP://” & strDomainName & “‘“ Set adoLDAPRS = adoLDAPCon.Execute(“select mail from ” § & strLDAP & ” WHERE objectClass = ‘user’”& § ” And samAccountName = ’” & strAccountName & “‘”) With adoLDAPRS If Not .EOF Then GetEmail = .Fields(“mail”) Else GetEmail = ““ End If End With adoLDAPRS.Close Set adoLDAPRS = Nothing Set adoLDAPCon = Nothing End Function |
Quite simple huh? I use this script as a frontend for my command line mailer mms.
Btw. I found this code in a newsgroup, but I forget where it was..

2 Comments
1 joe wrote:
This is nice thanks.
Can we search for email of other people (other than the logged in user), probably from active directory.?
2 Saj Thomas wrote:
how do i get get this email ID. docubind@docubindcommercial