Sending Mail to a Manager

See Also

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.

For example, you can add the modSendMailToMgr function to an action to notify a manager when an issue is opened or closed.

To use this example, add the function call to the script procedure on the Shared Script tab in the Workflow Process pane. Then, add the following example code to the beginning or end of the text in the Shared Script tab.

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