0

I created an email template in HTML which i call in my python code. I render the mail using MIMEMultipart() and sending it afterwards via SMTP server to Microsoft Outlook. I pass a variable to my html code and want to change the color if the value of the variable is higher then 100.

For that i did that:

<html xmlns:v="urn:schemas-microsoft-com:vml"
      xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:w="urn:schemas-microsoft-com:office:word"
      xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
      xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
      xmlns="http://www.w3.org/TR/REC-html40">

<head>
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
</head>
<body lang=DE link=blue vlink=purple style='word-wrap:break-word'>
    <script>
    <div class=WordSection1>
        function f_color() {
            if (document.getElementById('ID').value > '100') {
                document.getElementById('ID').style.color = "red";
            } else {
                document.getElementById('ID').style.color = "green";
            }
        }
        document.getElementById('ID').onchange = f_color;
    </script>
    <div class=WordSection1>
        <p class=MsoNormal>
            <span lang=EN-US style='font-size:11.0pt;font-family:Calibri,sans-serif;mso-ansi-language:EN-US'>
                <table id="myTable" style="width:100%">
                    <tr>
                        <td><b>{{ ID }}</b> </td>
                    </tr>
                </table>
            </span>
        </p>
    </div>
</body>
</html>

But it didn't change the color. I looked also in other related questions but didn't find any solution. I also didn't worked with coloring in html yet, so please indulgent.

asdf1234
  • 11
  • 2
  • 1. You do not have a form element with id="ID". Only form elements have .value and change events 2. Email clients do not execute JS so the Python will have to have some JS knowledgeable DOM and JS parser – mplungjan May 23 '23 at 09:14
  • You could try [CSS](https://stackoverflow.com/questions/31803300/coloring-the-text-depending-on-numeric-value-using-css) – mplungjan May 23 '23 at 09:15
  • Also you have `
    ` in the script tags which is illegal script
    – mplungjan May 23 '23 at 09:18
  • @mplungjan I never used DOM or JS parser, is there any other way? I think CSS isn't also a solution for me, because i get the value after running the script. Please correct me if i am wrong. – asdf1234 May 23 '23 at 10:49
  • Just generate the whole thing on the server without any JS. Change the red to green on the server that already knows the value `110 ` – mplungjan May 23 '23 at 12:02

0 Answers0