Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Emailing the User on Job Completion SMP 7.1 +

Created: 10 Oct 2013 • Updated: 10 Oct 2013 | 1 comment
Language Translations
michael cole's picture
+1 1 Vote
Login to vote

This article was inspired by a customer wishing to have the same functionality as in Deployment Server with regards to job emailing. The functionality was missing because the custom token for a User's email had to be created in CMS/ITMS, but existed natively in DS 6.9.

The link to the DS article is here   https://www-secure.symantec.com/connect/blogs/send-email-notification-tech-after-completed-job. I will link back here when published.

Disclaimer: During this article I will refer to the use of an SMTP server/service on the SMP. This is not something I would suggest in production, it is merely so that I did not require to build an exchange server for the purposes of sending an email in a test lab. It did happen to be a useful side exercise for testing environments needing email access. For email purposes in production environments we usually consider Microsoft Exchange, however the Notification Server settings allow you to configure any viable SMTP Server. Also, in this instance we are not going to go through the SMP for email, we will email direct from script. You may also know that 2008 R2 allows the installation of the SMTP feature under IIS which allows us to have a very nifty email sending facility on the SMP box. Once again, DO try this at home, DON'T try this at work. Whilst ten years ago we may have been having fun with anonymous SMTP relays, we've probably all grown up a little now.wink

Here is what this article will discuss

  1. Overview
  2. How to setup SMTP on your testing SMP box *testing only
  3. Creating a custom token to identify the user of a task
  4. Creating a job with VB to send a mail

Overview

The purpose of this article is to allow administrators to know when their long running tasks have finished by sending them an email. By this I am mostly referring to imaging tasks, although anything where you need an email at the end works.Hopefully someone can enjoy a cold one in the pub and get emailed when done smiley There are some issues with the current email automation that didn't make this easy. I am not going to discuss other methods here, but I will provide a working scenario you can use for your own benefit.

The hinge point of this is knowing who ran a task and then querying the database to join their email from AD to their username. When we get that email we need to tokenise it and use it in an email script.If you are using MS Exchange you need to consider the configuration of your SMTP relay, specifically from the point of view of a script and the security settings. In this example I am using anonymous access. Again...this is for testing only.

Setting up SMTP service (*testing only*)

There are two pieces i'd like to point out. A brief video: http://www.youtube.com/watch?v=IuBHxf1c7rE which I tested and works (since this is simple) and additionally some IIS 7 tweaking you need to do after: http://technet.microsoft.com/en-us/library/cc772058(v=ws.10).aspx

In short, install the SMTP feature to Windows 2008 as in the video and make the config changes to IIS6 manager. You then have to launch IIS7 manager - note the differences! Add an email address and configure security.

120px_iis7.JPG  IIS7 SMPTP settings120px_SMTP.JPG

You can still use the IIS6 manager for troubleshooting. One of the harder parts of troubleshooting the evaluation of tokens is seeing what happens after the job is sent. Luckily I found out exactly how to do that, it's a bit like reading NSE's in fact!

If you stop the service from IIS6 manager the emails sent stop by default in C:\inetpub\mailroot\Pickup where you see them as .EML files. If you open these and examine the text it will help you evaluate how you are doing. They may also be in a bad folder.

 

smtp-errorcheck.JPG

Anyway, enough of this huge digression. I just hoped to point out you can use this for testing and to give the background on how I can send from VB Script later - which is important.

Creating the Custom Token

This is the main event to pass on. We need to create a token like this:

token.JPG

Call it Usermail and copy/paste the SQL transact below, then save:

 

select top 1

igugd.Email

from TaskInstances ti

join TaskInstanceParents tip on ti.TaskInstanceGuid = tip.TaskInstanceGuid

join TaskInstanceSummaries tisum on tip.ParentTaskInstanceGuid = tisum.TaskInstanceGuid

right outer join Inv_Global_Windows_Users igwu on userid = right(tisum.ExecutedBy,((CHARINDEX('\',reverse(ExecutedBy))-1)))

join Inv_Global_User_General_Details igugd on igwu._ResourceGuid = igugd._ResourceGuid

where ti.ResourceGuid = '%COMPUTERID%'

order by tisum.StartTime DESC

 

Creating a VB script to send the mail

createvbjob.JPG

Couple of things to note here. In yellow marker are the tokens, blue underline are optional texts you can edit and the red circle on "2" means that it refers to an external SMTP server (alternative is 1 on localhost). This and the original script are taken from http://technet.microsoft.com/en-us/library/ee176585.aspx

' ===== Send Notification E-Mail =====

set objshell = createObject("wscript.shell")
dim date 
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "jobmonitorSMP71@waterville.local"
objEmail.To = "%USERMAIL%"
objEmail.Subject = "Job Complete - %COMPNAME%"
objEmail.Textbody = "This notification was sent to you as you initiated a Job on %COMPNAME% which finished at "&now
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "%NSSERVER%"
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
 
Once you create this script you can run it at the end of any job and it will run and email the username that ran the original SMP job. I've added a datestamp and tokenised the NSSERVER so the script is more portable, but this is all that is required to grant this function that DS had.
 
Although this technique worked for me and was tested in two environments, I can't guarantee it will work flawlessly under pressure in production, as well as the differences between exchange setup and SMTP as a simple service. The SQL query on the Token was tricky to come up with and sometimes reacted differently to many users at once. Nevertheless, the prinicpals are all intact and enough for anyone to re-use.
 
I hope this helped, please comment below if you found alternatives to share!

Comments 1 CommentJump to latest comment

burndtjammer's picture

It would be great to be able to have the NS send emails for all tasks pass or fail, but this is definitely something i have been looking for for a while. Thank you.

0
Login to vote