Finding a User's E-Mail Address in the User Directory
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
The following example uses the modFindUserEmailInUserList function to locate a user's e-mail address based on the user's SAMAccountName.
For example, you can add the modFindUserEmailInUserList function to an event to identify a user's e-mail address when an issue is opened or closed. Then, you can use the modSendMail function to send e-mail to that address.
To use this example, add the "Calling the Function" code to the appropriate script procedure, and add the "Example Script" code wherever you usually store functions.
Calling the Function
'// modFindUserEmailInUserList
'//
'// ----------------------------------------------------------------
ret = modFindUserEmailInUserList("owner")
call logger.printstring("user email from owner: " & ret & chr(13) & chr(10))
'// ----------------------------------------------------------------
Example Script
'// ----------------------------------------------------------------
'// Name : modFindUserEmailInUserList
'// Purpose : finds an e-mail address for the user from modUserList based on Session.Item() data
'//
'// Prereq : none
'// :
'// Inputs : strItem - name of Session.Item() value that equates to a SAMAccountName
'//
'// Return : User e-mail name if function succeeds, otherwise zero length string ""
'// ----------------------------------------------------------------
Function modFindUserEmailInUserList(strItem)
'// declarations
Dim strUL_SAM
Dim strUL_MAIL
'// init UL vars
strUL_SAM = "SAMAccountName"
strUL_MAIL = "mail"
'// assume failure
modFindUserEmailInUserList = ""
Set ulist = Session.userlist
On Error Resume Next
'// find user in userlist
ulist.MoveFirst
ulist.Find strUL_SAM & "='" & Session.Item(strItem) & "'"
'// check for fail
If Err Or ulist.EOF Or ulist.BOF Then
Exit Function
Else
On Error GoTo 0
modFindUserEmailInUserList = ulist(strUL_MAIL)
End If
End Function
See Also
Script Examples for SQL Server | Sending Mail Using SMTP | Finding a Manager in the User Directory | Sending Mail to a Manager | Calling a Stored Procedure