Home Analyst Portal

Can I send an notification email using a template from script ?

Stephane_BouillonStephane_Bouillon Customer Advanced IT Monkey ✭✭✭
Hi, I have a SMA Runbook activity in a service request offering. I'd like to send some emails from the script depending on certain conditions. Is there a CMDLet for that available ?

Best Answer

Answers

  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    I do not know for certain that there is not, but I have not seen one.  I consider this more tangentially related information than a firm answer to your question, but maybe this will be useful anyway.

    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.
  • Stephane_BouillonStephane_Bouillon Customer Advanced IT Monkey ✭✭✭
    Thanks for your reply Tom. I'm mainly looking at how I could reuse the mail templates already available rather than rewriting them in script.
  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    Then I am even more confident that no such thing exists (yet!), but this could be accomplished in SMA.

    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.
  • Stephane_BouillonStephane_Bouillon Customer Advanced IT Monkey ✭✭✭
    Thanks, do you happen to know which command to use to retrieve a Template based on its name ?
  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    edited April 2018
    Get-SCSMEmailTemplate | ?{$_.displayname -eq "TemplateNameHere"} | select -expandproperty Templatecollection

    @Tom_Hendricks - I love this idea of doing replaces on the properties in the template!  
  • Stephane_BouillonStephane_Bouillon Customer Advanced IT Monkey ✭✭✭
    Wow ! Thanks Roland, impressive !
Sign In or Register to comment.