Can I send an notification email using a template from script ?
Best Answer
-
Roland_Kind Partner Advanced IT Monkey ✭✭✭
Hi,
the enclosed PS script should do the work including appropriate language support by using some reflection
the example uses a notification based on comments - tested on SCSM 2016 but should work with minor adjustements on scsm2012 as well (dll path etc.)
regards
7
Answers
We have always either created a session with Exchange (due to the way the Exchange cmdlets work...long story) or imported the Exchange Web Services dll into PS, the same way the SMLets Exchange Connector does. Which one we use has more to do with the rest of the runbook than the actual merits of either method. For example, if we already need Exchange cmdlets loaded, we use that to send. If not, the answer is usually EWS.
Templates can be retrieved with cmdlets. I am unsure what would happen with the MP variables, however, because a workflow would not be processing it, as is usually the case with mail subscriptions. You would probably just see the variable names. If so, the good news is that it should be fairly simple to find and replace them with regular expressions since they follow a pattern.
So as long as you use the same MP variables in your mail templates fairly consistently, you could retrieve the email template, find/replace the variables with regular expressions (you would have to write the "mapping" for this) and then add the body, text, TO fields to the email commands of your choice.
@Tom_Hendricks - I love this idea of doing replaces on the properties in the template!
Hi,
the enclosed PS script should do the work including appropriate language support by using some reflection
the example uses a notification based on comments - tested on SCSM 2016 but should work with minor adjustements on scsm2012 as well (dll path etc.)
regards