change font color inside table td based on a variable value

I have a powershell script that sends mail as html. This is based on the result of SQL query which checks the database status (online or offline) and if it has any failed jobs for each projects (A,B,C).

$group1, $group2, $group5 = ‘ONLINE’ or ‘OFFLINE’

$group3, $group4, $group7 = List of failed jobs or ‘No Failed Job’

Here’s my request: if $group3, $group4, $group7 = ‘No Failed Job’, make the color font ‘No Failed Job’ red. Otherwise, normal default color.

$body = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE></HEAD>"
 $body += "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: TAHOMA; color: #000000""><P>"
 $body += "

<table style=""width:100%; border=1"">
    <th style=""text-align:left; color:blue"">Project </th>
    <th style=""text-align:left; color:blue"">DB Status</th>
    <th style=""text-align:left; color:blue"">Failed Job</th>
  <br />
    <td>Proj A</td>
    <td> Proj B </td>
    <td> Proj C</td>
</table><br /><br />"

This is easily done by adding a class to the table call and a corresponding CSS selector (in regular HTML).
But since this is for email, maybe go for the moe archaic and dirty in-line style.

How you do that according to database results, that depends on a few things.
What server side language are you using? The variables look like PHP, but I’m not making assumptions.
In what format/structure is the data you get from the database?

I’m using powershell to send the mail with html. Powershell script which invoke a sqlcmd to execute queries to find DB online status and failed job.

# commands below invoke sqlcmd to execute queries to get status and job failed and save them to text files.
cmd.exe -/c "C:\Users\lan\projA.bat" 
cmd.exe -/c "C:\Users\lan\projB.bat" 
cmd.exe -/c "C:\Users\lan\projC.bat" 

$path1 = "C:\Users\lan\temp\sqlsrvr\projA_status.txt"   
$path2 = "C:\Users\lan\temp\sqlsrvr\projB_status.txt"   
$path3 = "C:\Users\lan\temp\sqlsrvr\projA_jobfailed.txt"   
$path4 = "C:\Users\lan\temp\sqlsrvr\projB_jobfailed.txt"   

$path5 = "C:\Users\lan\temp\sqlsrvr\projC_status.txt"   
$path7 = "C:\Users\lan\temp\sqlsrvr\projC_jobfailed.txt"   

$groups1 = (Get-Content $path1) -join '<br>'  
$groups2 = (Get-Content $path2) -join '<br>'  
$groups3 = (Get-Content $path3) -join '<br>'  
$groups4 = (Get-Content $path4) -join '<br>' 

$groups5 = (Get-Content $path5) -join '<br>'  
$groups7 = (Get-Content $path7) -join '<br>'  

i’m new to html/css. i don’t know how to implement “archaic and dirty in-line style.” or add a class to the table call and a corresponding CSS selector (in regular HTML).

i’d appreciate some examples.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.