Sitecore Content Hub - Approved Asset Email

 Today I am going to show you how you can have Content Hub send emails to users that belong to a certain user group when an asset is approved. 

There are a few steps that need to be followed to accomplish this: 

  1. Create an Email Template
  2. Create a user group
  3. Create the script
  4. Create the action
  5. Create the trigger
So let's get started. There's currently no way to create email templates using the Content Hub graphical interface, therefore, we will use the REST API to do this. 

We need to authenticate ourselves to make further calls using the API: 

 POST: https://{hostname}/api/authenticate  
 Body:   
 {  
 "user_name":"YourContentHubUsername",  
 "password":"YourPassword"  
 }  

The response will be something like this: 

 {  
   "token": "b9xxxfeac7fe41234544286e27f5xxxx"  
 }  

Once you have the token, you can create the email template by using the entities endpoint: 

 POST: https://{hostname}/api/entities  
 Header:   
 X-Auth-Token: b9xxxfeac7fe41234544286e27f5xxxx (The token you got on the previous step)  
 Body:  
 {  
   "identifier": "M.Mailing.Template.SR.ApprovedAsset",  
   "cultures": [  
     "en-US"  
   ],  
   "properties": {  
     "M.Mailing.TemplateName": "ApprovedAsset",  
     "M.Mailing.TemplateLabel": {  
       "en-US": "Approved Asset"  
     },  
     "M.Mailing.TemplateDescription": {  
       "en-US": "Notifies admins that an asset has been approved"  
     }  
   },  
   "entitydefinition": {  
     "href": "https://{hostname}/api/entitydefinitions/M.Mailing.Template",  
     "title": "Approved Asset Entity"  
   }  
 }  

Once you've received a successful response from Content Hub, you can navigate to the email templates screen and you should see your newly created template: 


Let's now edit our template, click on the pencil button on the right and update the email body with the following: 
 <!doctype html>  
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">  
 <head>  
   <!-- NAME: 1 COLUMN -->  
   <!--[if gte mso 15]>  
   <xml>  
     <o:OfficeDocumentSettings>  
     <o:AllowPNG/>  
     <o:PixelsPerInch>96</o:PixelsPerInch>  
     </o:OfficeDocumentSettings>  
   </xml>  
   <![endif]-->  
   <meta charset="UTF-8">  
   <meta http-equiv="X-UA-Compatible" content="IE=edge">  
   <meta name="viewport" content="width=device-width, initial-scale=1">  
   <title>*|MC:SUBJECT|*</title>  
   <style type="text/css">  
     p {  
       margin: 10px 0;  
       padding: 0;  
     }  
     table {  
       border-collapse: collapse;  
     }  
     h1, h2, h3, h4, h5, h6 {  
       display: block;  
       margin: 0;  
       padding: 0;  
     }  
     img, a img {  
       border: 0;  
       height: auto;  
       outline: none;  
       text-decoration: none;  
     }  
     body, #bodyTable, #bodyCell {  
       height: 100%;  
       margin: 0;  
       padding: 0;  
       width: 100%;  
     }  
     #outlook a {  
       padding: 0;  
     }  
     img {  
       -ms-interpolation-mode: bicubic;  
     }  
     table {  
       mso-table-lspace: 0pt;  
       mso-table-rspace: 0pt;  
     }  
     .ReadMsgBody {  
       width: 100%;  
     }  
     .ExternalClass {  
       width: 100%;  
     }  
     p, a, li, td, blockquote {  
       mso-line-height-rule: exactly;  
     }  
       a[href^=tel], a[href^=sms] {  
         color: inherit;  
         cursor: default;  
         text-decoration: none;  
       }  
     p, a, li, td, body, table, blockquote {  
       -ms-text-size-adjust: 100%;  
       -webkit-text-size-adjust: 100%;  
     }  
     .ExternalClass, .ExternalClass p, .ExternalClass td, .ExternalClass div, .ExternalClass span, .ExternalClass font {  
       line-height: 100%;  
     }  
     a[x-apple-data-detectors] {  
       color: inherit !important;  
       text-decoration: none !important;  
       font-size: inherit !important;  
       font-family: inherit !important;  
       font-weight: inherit !important;  
       line-height: inherit !important;  
     }  
     #bodyCell {  
       padding: 10px;  
     }  
     .templateContainer {  
       max-width: 600px !important;  
     }  
     a.mcnButton {  
       display: block;  
     }  
     .mcnImage {  
       vertical-align: bottom;  
     }  
     .mcnTextContent {  
       word-break: break-word;  
     }  
       .mcnTextContent img {  
         height: auto !important;  
       }  
     .mcnDividerBlock {  
       table-layout: fixed !important;  
     }  
     /*  
     tab Page  
     section Background Style  
     tip Set the background color and top border for your email. You may want to choose colors that match your company's branding.  
     */  
     body, #bodyTable {  
       /*editable*/ background-color: #f5f5f5;  
     }  
     /*  
     tab Page  
     section Background Style  
     tip Set the background color and top border for your email. You may want to choose colors that match your company's branding.  
     */  
     #bodyCell {  
       /*editable*/ border-top: 0;  
     }  
     /*  
     tab Page  
     section Email Border  
     tip Set the border for your email.  
     */  
     .templateContainer {  
       /*editable*/ border: 0;  
     }  
     /*  
     tab Page  
     section Heading 1  
     tip Set the styling for all first-level headings in your emails. These should be the largest of your headings.  
     style heading 1  
     */  
     h1 {  
       /*editable*/ color: #212121;  
       /*editable*/ font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;  
       /*editable*/ font-size: 26px;  
       /*editable*/ font-style: normal;  
       /*editable*/ font-weight: normal;  
       /*editable*/ line-height: 125%;  
       /*editable*/ letter-spacing: normal;  
       /*editable*/ text-align: center;  
     }  
     /*  
     tab Page  
     section Heading 2  
     tip Set the styling for all second-level headings in your emails.  
     style heading 2  
     */  
     h2 {  
       /*editable*/ color: #222222;  
       /*editable*/ font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;  
       /*editable*/ font-size: 22px;  
       /*editable*/ font-style: normal;  
       /*editable*/ font-weight: normal;  
       /*editable*/ line-height: 125%;  
       /*editable*/ letter-spacing: normal;  
       /*editable*/ text-align: center;  
     }  
     /*  
     tab Page  
     section Heading 3  
     tip Set the styling for all third-level headings in your emails.  
     style heading 3  
     */  
     h3 {  
       /*editable*/ color: #222222;  
       /*editable*/ font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;  
       /*editable*/ font-size: 16px;  
       /*editable*/ font-style: normal;  
       /*editable*/ font-weight: bold;  
       /*editable*/ line-height: 125%;  
       /*editable*/ letter-spacing: normal;  
       /*editable*/ text-align: center;  
     }  
     /*  
     tab Page  
     section Heading 4  
     tip Set the styling for all fourth-level headings in your emails. These should be the smallest of your headings.  
     style heading 4  
     */  
     h4 {  
       /*editable*/ color: #666666;  
       /*editable*/ font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;  
       /*editable*/ font-size: 16px;  
       /*editable*/ font-style: normal;  
       /*editable*/ font-weight: normal;  
       /*editable*/ line-height: 125%;  
       /*editable*/ letter-spacing: normal;  
       /*editable*/ text-align: center;  
     }  
     /*  
     tab Preheader  
     section Preheader Style  
     tip Set the background color and borders for your email's preheader area.  
     */  
     #templatePreheader {  
       /*editable*/ background-color: #f5f5f5;  
       /*editable*/ background-image: none;  
       /*editable*/ background-repeat: no-repeat;  
       /*editable*/ background-position: center;  
       /*editable*/ background-size: cover;  
       /*editable*/ border-top: 0;  
       /*editable*/ border-bottom: 0;  
       /*editable*/ padding-top: 0px;  
       /*editable*/ padding-bottom: 24px;  
     }  
       /*  
     tab Preheader  
     section Preheader Text  
     tip Set the styling for your email's preheader text. Choose a size and color that is easy to read.  
     */  
       #templatePreheader .mcnTextContent, #templatePreheader .mcnTextContent p {  
         /*editable*/ color: #f5f5f5;  
         /*editable*/ font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;  
         /*editable*/ font-size: 12px;  
         /*editable*/ line-height: 150%;  
         /*editable*/ text-align: left;  
       }  
         /*  
     tab Preheader  
     section Preheader Link  
     tip Set the styling for your email's preheader links. Choose a color that helps them stand out from your text.  
     */  
         #templatePreheader .mcnTextContent a, #templatePreheader .mcnTextContent p a {  
           /*editable*/ color: #999999;  
           /*editable*/ font-weight: normal;  
           /*editable*/ text-decoration: underline;  
         }  
     /*  
     tab Header  
     section Header Style  
     tip Set the background color and borders for your email's header area.  
     */  
     #templateHeader {  
       /*editable*/ background-color: #ffffff;  
       /*editable*/ background-image: none;  
       /*editable*/ background-repeat: no-repeat;  
       /*editable*/ background-position: center;  
       /*editable*/ background-size: cover;  
       /*editable*/ border-top: 0;  
       /*editable*/ border-bottom: 0;  
       /*editable*/ padding-top: 40px;  
       /*editable*/ padding-bottom: 0px;  
     }  
       /*  
     tab Header  
     section Header Text  
     tip Set the styling for your email's header text. Choose a size and color that is easy to read.  
     */  
       #templateHeader .mcnTextContent, #templateHeader .mcnTextContent p {  
         /*editable*/ color: #ffffff;  
         /*editable*/ font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;  
         /*editable*/ font-size: 13px;  
         /*editable*/ line-height: 200%;  
         /*editable*/ text-align: left;  
       }  
         /*  
     tab Header  
     section Header Link  
     tip Set the styling for your email's header links. Choose a color that helps them stand out from your text.  
     */  
         #templateHeader .mcnTextContent a, #templateHeader .mcnTextContent p a {  
           /*editable*/ color: #19a5a2;  
           /*editable*/ font-weight: normal;  
           /*editable*/ text-decoration: underline;  
         }  
     /*  
     tab Body  
     section Body Style  
     tip Set the background color and borders for your email's body area.  
     */  
     #templateBody {  
       /*editable*/ background-color: #ffffff;  
       /*editable*/ background-image: none;  
       /*editable*/ background-repeat: no-repeat;  
       /*editable*/ background-position: center;  
       /*editable*/ background-size: cover;  
       /*editable*/ border-top: 0;  
       /*editable*/ border-bottom: 0;  
       /*editable*/ padding-top: 0px;  
       /*editable*/ padding-bottom: 48px;  
     }  
       /*  
     tab Body  
     section Body Text  
     tip Set the styling for your email's body text. Choose a size and color that is easy to read.  
     */  
       #templateBody .mcnTextContent, #templateBody .mcnTextContent p {  
         /*editable*/ color: #212121;  
         /*editable*/ font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;  
         /*editable*/ font-size: 14px;  
         /*editable*/ line-height: 200%;  
         /*editable*/ text-align: center;  
       }  
         /*  
     tab Body  
     section Body Link  
     tip Set the styling for your email's body links. Choose a color that helps them stand out from your text.  
     */  
         #templateBody .mcnTextContent a, #templateBody .mcnTextContent p a {  
           /*editable*/ color: #19a5a2;  
           /*editable*/ font-weight: normal;  
           /*editable*/ text-decoration: none;  
         }  
     /*  
     tab Footer  
     section Footer Style  
     tip Set the background color and borders for your email's footer area.  
     */  
     #templateFooter {  
       /*editable*/ background-color: #f5f5f5;  
       /*editable*/ background-image: none;  
       /*editable*/ background-repeat: no-repeat;  
       /*editable*/ background-position: center;  
       /*editable*/ background-size: cover;  
       /*editable*/ border-top: 0;  
       /*editable*/ border-bottom: 0;  
       /*editable*/ padding-top: 9px;  
       /*editable*/ padding-bottom: 9px;  
     }  
       /*  
     tab Footer  
     section Footer Text  
     tip Set the styling for your email's footer text. Choose a size and color that is easy to read.  
     */  
       #templateFooter .mcnTextContent, #templateFooter .mcnTextContent p {  
         /*editable*/ color: #aaaaaa;  
         /*editable*/ font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;  
         /*editable*/ font-size: 12px;  
         /*editable*/ line-height: 150%;  
         /*editable*/ text-align: center;  
       }  
         /*  
     tab Footer  
     section Footer Link  
     tip Set the styling for your email's footer links. Choose a color that helps them stand out from your text.  
     */  
         #templateFooter .mcnTextContent a, #templateFooter .mcnTextContent p a {  
           /*editable*/ color: #999999;  
           /*editable*/ font-weight: normal;  
           /*editable*/ text-decoration: underline;  
         }  
     media only screen and (min-width:768px) {  
       .templateContainer;  
     {  
       width: 600px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       body,table,td,p,a,li,blockquote;  
     {  
       -webkit-text-size-adjust: none !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       body;  
     {  
       width: 100% !important;  
       min-width: 100% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       #bodyCell;  
     {  
       padding-top: 10px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImage;  
     {  
       width: 100% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnCartContainer,.mcnCaptionTopContent,.mcnRecContentContainer,.mcnCaptionBottomContent,.mcnTextContentContainer,.mcnBoxedTextContentContainer,.mcnImageGroupContentContainer,.mcnCaptionLeftTextContentContainer,.mcnCaptionRightTextContentContainer,.mcnCaptionLeftImageContentContainer,.mcnCaptionRightImageContentContainer,.mcnImageCardLeftTextContentContainer,.mcnImageCardRightTextContentContainer;  
     {  
       max-width: 100% !important;  
       width: 100% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnBoxedTextContentContainer;  
     {  
       min-width: 100% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImageGroupContent;  
     {  
       padding: 9px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnCaptionLeftContentOuter .mcnTextContent,.mcnCaptionRightContentOuter .mcnTextContent;  
     {  
       padding-top: 9px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImageCardTopImageContent,.mcnCaptionBlockInner .mcnCaptionTopContent:last-child .mcnTextContent;  
     {  
       padding-top: 18px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImageCardBottomImageContent;  
     {  
       padding-bottom: 9px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImageGroupBlockInner;  
     {  
       padding-top: 0 !important;  
       padding-bottom: 0 !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImageGroupBlockOuter;  
     {  
       padding-top: 9px !important;  
       padding-bottom: 9px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnTextContent,.mcnBoxedTextContentColumn;  
     {  
       padding-right: 18px !important;  
       padding-left: 18px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcnImageCardLeftImageContent,.mcnImageCardRightImageContent;  
     {  
       padding-right: 18px !important;  
       padding-bottom: 0 !important;  
       padding-left: 18px !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       .mcpreview-image-uploader;  
     {  
       display: none !important;  
       width: 100% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Heading 1  
     tip Make the first-level headings larger in size for better readability on small screens.  
     */  
       h1;  
     {  
       /*editable*/ font-size: 22px !important;  
       /*editable*/ line-height: 125% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Heading 2  
     tip Make the second-level headings larger in size for better readability on small screens.  
     */  
       h2;  
     {  
       /*editable*/ font-size: 20px !important;  
       /*editable*/ line-height: 125% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Heading 3  
     tip Make the third-level headings larger in size for better readability on small screens.  
     */  
       h3;  
     {  
       /*editable*/ font-size: 18px !important;  
       /*editable*/ line-height: 125% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Heading 4  
     tip Make the fourth-level headings larger in size for better readability on small screens.  
     */  
       h4;  
     {  
       /*editable*/ font-size: 16px !important;  
       /*editable*/ line-height: 150% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Boxed Text  
     tip Make the boxed text larger in size for better readability on small screens. We recommend a font size of at least 16px.  
     */  
       .mcnBoxedTextContentContainer .mcnTextContent,.mcnBoxedTextContentContainer .mcnTextContent p;  
     {  
       /*editable*/ font-size: 14px !important;  
       /*editable*/ line-height: 150% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Preheader Visibility  
     tip Set the visibility of the email's preheader on small screens. You can hide it to save space.  
     */  
       #templatePreheader;  
     {  
       /*editable*/ display: block !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Preheader Text  
     tip Make the preheader text larger in size for better readability on small screens.  
     */  
       #templatePreheader .mcnTextContent,#templatePreheader .mcnTextContent p;  
     {  
       /*editable*/ font-size: 14px !important;  
       /*editable*/ line-height: 150% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Header Text  
     tip Make the header text larger in size for better readability on small screens.  
     */  
       #templateHeader .mcnTextContent,#templateHeader .mcnTextContent p;  
     {  
       /*editable*/ font-size: 16px !important;  
       /*editable*/ line-height: 150% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Body Text  
     tip Make the body text larger in size for better readability on small screens. We recommend a font size of at least 16px.  
     */  
       #templateBody .mcnTextContent,#templateBody .mcnTextContent p;  
     {  
       /*editable*/ font-size: 16px !important;  
       /*editable*/ line-height: 150% !important;  
     }  
     }  
     media only screen and (max-width: 480px) {  
       /*  
     tab Mobile Styles  
     section Footer Text  
     tip Make the footer content text larger in size for better readability on small screens.  
     */  
       #templateFooter .mcnTextContent,#templateFooter .mcnTextContent p;  
     {  
       /*editable*/ font-size: 14px !important;  
       /*editable*/ line-height: 150% !important;  
     }  
     }  
   </style>  
   <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">  
 </head>  
 <body style="height: 100%;margin: 0;padding: 0;width: 100%;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;background-color: #f5f5f5;">  
   <center>  
     <table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;height: 100%;margin: 0;padding: 0;width: 100%;background-color: #f5f5f5;">  
       <tr>  
         <td align="center" valign="top" id="bodyCell" style="mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;height: 100%;margin: 0;padding: 10px;width: 100%;border-top: 0;">  
           <!-- BEGIN TEMPLATE // -->  
           <!--[if gte mso 9]>  
           <table align="center" border="0" cellspacing="0" cellpadding="0" width="600" style="width:600px;">  
           <tr>  
           <td align="center" valign="top" width="600" style="width:600px;">  
           <![endif]-->  
           <table border="0" cellpadding="0" cellspacing="0" width="100%" class="templateContainer" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;border: 0;max-width: 600px !important;">  
             <tr>  
               <td valign="top" id="templatePreheader" style="mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;background-color: #f5f5f5;background-image: none;background-repeat: no-repeat;background-position: center;background-size: cover;border-top: 0;border-bottom: 0;padding-top: 0px;padding-bottom: 24px;">  
                 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnTextBlock" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                   <tbody class="mcnTextBlockOuter">  
                     <tr>  
                       <td valign="top" class="mcnTextBlockInner" style="padding-top: 9px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                         <!--[if mso]>  
                         <table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100%;">  
                         <tr>  
                         <![endif]-->  
                         <!--[if mso]>  
                         <td valign="top" width="600" style="width:600px;">  
                         <![endif]-->  
                         <table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width: 100%;min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;" width="100%" class="mcnTextContentContainer">  
                           <tbody>  
                             <tr>  
                               <td valign="top" class="mcnTextContent" style="padding-top: 0;padding-right: 18px;padding-bottom: 9px;padding-left: 18px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;word-break: break-word;color: #f5f5f5;font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;font-size: 12px;line-height: 150%;text-align: left;">  
                                 <style type="text/css">  
                                   p.light {  
                                     color: #757575 !important;  
                                     font-size: 13px !important;  
                                   }  
                                 </style>  
                               </td>  
                             </tr>  
                           </tbody>  
                         </table>  
                         <!--[if mso]>  
                         </td>  
                         <![endif]-->  
                         <!--[if mso]>  
                         </tr>  
                         </table>  
                         <![endif]-->  
                       </td>  
                     </tr>  
                   </tbody>  
                 </table><table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnImageBlock" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                   <tbody class="mcnImageBlockOuter">  
                     <tr>  
                       <td valign="top" style="padding: 0px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;" class="mcnImageBlockInner">  
                         <table align="left" width="100%" border="0" cellpadding="0" cellspacing="0" class="mcnImageContentContainer" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                           <tbody>  
                             <tr>  
                               <td class="mcnImageContent" valign="top" style="padding-right: 0px;padding-left: 0px;padding-top: 0;padding-bottom: 0;text-align: center;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                                 <img align="center" alt="Logo" src="{{m_url 'css/themes/base/img/m-logo-48.png'}}" width="48" style="max-width: 48px;padding-bottom: 0;display: inline !important;vertical-align: bottom;border: 0;height: auto;outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;" class="mcnImage">  
                               </td>  
                             </tr>  
                           </tbody>  
                         </table>  
                       </td>  
                     </tr>  
                   </tbody>  
                 </table>  
               </td>  
             </tr>  
             <tr>  
               <td valign="top" id="templateHeader" style="mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;background-color: #ffffff;background-image: none;background-repeat: no-repeat;background-position: center;background-size: cover;border-top: 0;border-bottom: 0;padding-top: 40px;padding-bottom: 0px;">  
                 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnBoxedTextBlock" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                   <!--[if gte mso 9]>  
                   <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%">  
                   <![endif]-->  
                   <tbody class="mcnBoxedTextBlockOuter">  
                     <tr>  
                       <td valign="top" class="mcnBoxedTextBlockInner" style="mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                         <!--[if gte mso 9]>  
                         <td align="center" valign="top" ">  
                         <![endif]-->  
                         <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="min-width: 100%;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;" class="mcnBoxedTextContentContainer">  
                           <tbody>  
                             <tr>  
                               <td style="padding-top: 9px;padding-left: 18px;padding-bottom: 9px;padding-right: 18px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                                 <table border="0" cellpadding="18" cellspacing="0" class="mcnTextContentContainer" width="100%" style="min-width: 100% !important;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">  
                                   <tbody>  
                                     <tr>  
                                       <td valign="top" class="mcnTextContent" style="font-weight: normal;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;word-break: break-word;color: #ffffff;font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;font-size: 13px;line-height: 200%;text-align: left;">  
                                         <h1 style="display: block;margin: 0;padding: 0;color: #212121;font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 26px;font-style: normal;font-weight: normal;line-height: 125%;letter-spacing: normal;text-align: center;">An asset has been approved!</h1>  
                                       </td>  
                                     </tr>  
                                                                                           <tr>  
                                       <td valign="top" class="mcnTextContent" style="font-weight: normal;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;word-break: break-word;color: #ffffff;font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;font-size: 13px;line-height: 200%;text-align: left;">  
                                         <a href="https://{hostname}/en-us/asset/{{AssetId}}" style="display: block;margin: 0;padding: 0;color: #212121;font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size: 26px;font-style: normal;font-weight: normal;line-height: 125%;letter-spacing: normal;text-align: center;">View Asset</a>  
                                       </td>  
                                     </tr>  
                                   </tbody>  
                                 </table>  
                               </td>  
                             </tr>  
                           </tbody>  
                         </table>  
                         <!--[if gte mso 9]>  
                         </td>  
                         <![endif]-->  
                         <!--[if gte mso 9]>  
                         </tr>  
                         </table>  
                         <![endif]-->  
                       </td>  
                     </tr>  
                   </tbody>  
                 </table>  
               </td>  
             </tr>  
             <tr>  
               <td valign="top" id="templateFooter" style="mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;background-color: #f5f5f5;background-image: none;background-repeat: no-repeat;background-position: center;background-size: cover;border-top: 0;border-bottom: 0;padding-top: 9px;padding-bottom: 9px;"></td>  
             </tr>  
           </table>  
           <!--[if gte mso 9]>  
           </td>  
           </tr>  
           </table>  
           <![endif]-->  
           <!-- // END TEMPLATE -->  
         </td>  
       </tr>  
     </table>  
   </center>  
 </body>  
 </html>  


You can modify this email template body to fit your needs, in fact, I just modified one of the existing templates that were already available in Content Hub. You need to update the {hostnameto match your Content Hub instance's url. Also note there's a token {{AssetId}} that will be replaced with our script before the email is sent. This email template will basically send an email like this: 




Let's now add a new User Group. This user group will be assigned to all the users that need to receive these custom emails: 




Now that we have our email template ready and our custom user group, it's time to create the Script:


The code we are going to use is the following (this code is a modification of Vasiliy Fomichev's code here: https://www.cmsbestpractices.com/how-to-send-emails-in-sitecore-content-hub/):

 using Stylelabs.M.Base.Querying;  
 using Stylelabs.M.Sdk.Contracts.Base;  
 using Stylelabs.M.Sdk.Contracts.Notifications;  
 using Stylelabs.M.Sdk.Models.Notifications;  
 using System;  
 using System.Collections.Generic;  
 using System.Globalization;  
 using System.Text;  
 using System.Threading.Tasks;  
 using System.Linq;  
 const string emailTemplatename = "ApprovedAsset";  

   var groupId = MClient.Users.GetUserGroupAsync("SR.CustomEmailNotifications").Result.Id;  
   var query = Query.CreateQuery(entities => from e in entities   
                        where e.DefinitionName == "User"  
                        select e);  
   var users = MClient.Querying.QueryAsync(query, new EntityLoadConfiguration { RelationLoadOption = RelationLoadOption.All }).Result;  
   var groupUsers = new List<IEntity>();  
   foreach (var user in users.Items)  
   {  
     var groupRelation = user.GetRelation<IChildToManyParentsRelation>("UserGroupToUser");  
     if (groupRelation.Parents.Contains(groupId ?? 0)) // nullable ID, provide fallback  
     {  
       groupUsers.Add(user);  
     }  
   }  
   var userNames = MClient.Users.GetUsernamesAsync(groupUsers.Select(i => i.Id ?? 0).ToList()).Result?.Select(i => i.Value).ToList();  
   var notificationRequest = new MailRequestByUsername  
   {  
     MailTemplateName = emailTemplatename,  
     Recipients = userNames  
   };  
   var entityModified = Context.Target as IEntity;  
   notificationRequest.Variables.Add("AssetId", entityModified.Id);  
   await MClient.Notifications.SendEmailNotificationAsync(notificationRequest);  

Now we need to create our Action


Let's now add our Trigger:  




And that is it! once an asset is approved you will get the email with the format defined on your email template! You can click on the "View Asset" link and you will get redirected to the appropriate asset! 


Happy scripting! 

Comments