Share via


Sending Mail to a Manager

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 calls the modFindMgrEmailInUserList function to find the manager's e-mail address and then uses the modSendMailToMgr function to send the e-mail to the manager using SMTP. SMTP is a member of the TCP/IP suite of protocols that governs the exchange of electronic mail between message transfer agents. To use this example, you must have SMTP running.

You can add the modSendMailToMgr function to an event to notify a manager when an issue is opened or closed.

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

'// modSendMailToMgr
'//
'// ---------------------------------------------------------------
    ret= modSendMailToMgr("owner", "default@microsoft.com", "UserName@microsoft.com", "test Subject", "test body")
    call logger.printstring("send mail to mgr return value: " & ret & chr(13) & chr(10))
'// ---------------------------------------------------------------

Example Script

'// ---------------------------------------------------------------
'// Name      : modSendMailToMgr
'// Purpose   : send mail to user's manager using SMTP
'//
'// Prereq    : assumes that you have a smarthost assigned in the SMTP Settings to route
'//           : mail using Exchange
'// Inputs    : strItem - name of Session.Item() value that equates to a SAMAccountName
'//           : strDefault - where to send e-mail if unable to find user or manager
'//           : strFrom - name to use for sending e-mail
'//           : strSubject - subject of e-mail
'//           : strBody - body of e-mail
'//
'// Return    : true if function succeeds, otherwise false
'// ---------------------------------------------------------------
Function modSendMailToMgr(strItem, strDefault, strFrom, strSubject, strBody)

    '// declarations
    Dim strManager
  
    '// assume failure
    modSendMailToMgr = False

    '// get manager
    strManager = modFindMgrEmailInUserList(strItem)
    
    '// check for empty
    If strManager = "" Then strManager = strDefault
    
    '// send mail
    modSendMailToMgr = modSendMail(strManager, strFrom, strSubject, strBody)
    
End Function

See Also

Script Examples for SQL Server | Finding a User's E-Mail Address in the User Directory | Sending Mail Using SMTP | Finding a Manager in the User Directory | Calling a Stored Procedure