title: Add header and text color in HTML table email body based on disk usage condition using Python
body: <p>I am sending out an html table in an email body using python. The html table consists of disk usage and I need to add the header (first row) and text in red in the table when disk usage is above 80 percent.</p>
  <p>This is the code I'm using that works to get the email with colouring the text but it does not include the headers (server,total size, total data, usage in %):</p>
  <pre class="lang-py prettyprint-override"><code>me = 'noreply@automationtest.com'
  
  server = 'some smtp server'
  you = 'email@someautomation.com'
  
  text = &quot;&quot;&quot;
  {table}
  &quot;&quot;&quot;
  
  html = &quot;&quot;&quot;
  &lt;html&gt;
  &lt;head&gt;
  &lt;style&gt; 
    table, th, td {{ border: 1px solid black; border-collapse: collapse; }}
    th, td {{ padding: 5px; }}
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;&lt;p style=&quot;font-family:verdana&quot;&gt;Hi,&lt;/p&gt;
  &lt;p style=&quot;font-family:verdana&quot;&gt;sometext&lt;/p&gt;
  {table}
  &lt;p style=&quot;font-family:verdana&quot;&gt;sometext&lt;/p&gt;
  &lt;p style=&quot;font-family:verdana&quot;&gt;Regards&lt;/p&gt;
  &lt;p style=&quot;font-family:verdana&quot;&gt;someme&lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  &quot;&quot;&quot; 
  
  with open('files/file.csv') as input_file:
      reader = DictReader(input_file)
      data = list(reader)
      for row in data:
        row['Usage in %'] = pd.to_numeric(row['Usage in %'])
        if row['Usage in %'] &gt;= 80:
        row['Usage in %'] = &quot;&lt;p style='color:red'&gt;%s&lt;/p&gt;&quot;%row['Usage in %']
  
  
  text = text.format(table=tabulate(data, headers=&quot;firstrow&quot;, tablefmt=&quot;grid&quot;))
  
  html = html.format(table=tabulate(data, headers=&quot;firstrow&quot;, tablefmt=&quot;unsafehtml&quot;))
  message = MIMEMultipart(&quot;alternative&quot;, None, [MIMEText(text), MIMEText(html,'html')])
  print(html)
  
  
  message['From'] = me
  message['To'] = you
  server = smtplib.SMTP(server)
  server.ehlo()
  server.starttls()
  server.login(me, password)
  server.sendmail(me, you, message.as_string())
  server.quit()
  </code></pre>
  <p>I'm getting the below output with text color but without the header:</p>
  <p><a href="https://i.stack.imgur.com/pmxOk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pmxOk.png" alt="" /></a></p>
  <p>Expected output:</p>
  <p><a href="https://i.stack.imgur.com/dnBe9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dnBe9.png" alt="" /></a></p>
  <p>Any help is greatly appreciated.</p>