Watcher Email Output Not Preserving HTML Cell Colors

Hello Team,

Could you please share if it is possible to have color coding while sending email via Watcher?
Like if OK = the cell should be Green in the table which is sent via Watcher & for NOT OK = Red.

I tried but it seems the style parameters are being dropped even tried updating the elasticsearch.yml with below config but it did not help :

xpack.notification.email.html.sanitization.allow: _tables, _blocks, _formatting, _links, img:embedded
xpack.notification.email.html.sanitization.disallow: script, style

Any pointers on how to proceed or if it is possible or not?

Thank you !

Could you post a watch that reproduces this? Have you tried setting xpack.notification.email.html.sanitization.enabled to false, just to see if that solves the problem (I understand that you probably don't want to do that in production, but I'm just curious if it solves the problem).

1 Like

Thank you @Keith_Massey

Yes, using this option color coding works as required. But how to make it happen in Production?

Thanks!!

I'm not sure yet. Can you post a watch that reproduces this?

Sure.

Please find below details :

Test Watcher :

{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "none": {}
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "to": [
          "myemail@id.com"
        ],
        "subject": "Hello World Watch",
        "body": {
          "html": """
            <html>
              <body>
                <h3>Notification Table</h3>
                <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse; width: 100%; text-align: center;">
                  <tr style="background-color: #f2f2f2;">
                    <th style="width: 50%;">Critical Alerts</th>
                    <th style="width: 50%;">Normal Updates</th>
                  </tr>
                  <tr>
                    <td style="background-color: #F44336; color: white;">This is a critical alert!</td>
                    <td style="background-color: #4CAF50; color: white;">This is a normal update.</td>
                  </tr>
                </table>
                <p style="margin-top: 20px;">Thanks,<br/>ELK team</p>
              </body>
            </html>
          """
        }
      }
    }
  }
}

elasticsearch.yml setting :

xpack.notification.email.html.sanitization.enabled : false

Sample email received :

If i remove the above entry from elasticsearch.yml :

Sample email received :

Thanks!!

You need to add _styles to your 'allow' setting as documented here.

Thanks @angelo for the suggestion.

Using styles , i confirm it is working as expected.

xpack.notification.email.html.sanitization.allow: _tables, _formatting, _styles

Thanks!!