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.
Here is what this article will discuss
- How to setup SMTP on your testing SMP box *testing only
- Creating a custom token to identify the user of a task
- Creating a job with VB to send a mail
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 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.
IIS7 SMPTP settings
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.
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:
Call it Usermail and copy/paste the SQL transact below, then save:
select top 1
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
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 =====