Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29929

Dataframe table in email body should be colored based on the condition in dataframe

$
0
0

****I want to highlight the row(out of sync) with red color so that my team can act on out of sync issues upon watching the email immediately. Can someone help here.**** Here is my code

def bibreport():
    finaldatabib = []
    data={}
    if some condition:
        data['SyncStatus'] = "In Sync"
        finaldatabib.append(data)
    else:
        data['SyncStatus'] = "out of Sync"
        finaldatabib.append(data)

    dfbib = pd.DataFrame(finaldatabib)
    dfbib.index.name = "SNO"
    colsbib = ['SyncStatus']
    databib=dfbib
    return databib,colsbib

def sendmail(databib,colsbib):
    email_user = 'xxx@email.com'
    email_send = ['yyy@email.com']
    html = """<html>
<html>
<head>
<style>
  table, th, td {{ border: 2px solid black; border-collapse: collapse; }}
  th, td {{ padding: 4px; }}
</style>
</head>
<body><p>Dear Team, </p>
<p>Please find the details below.</p>
{table}
<p>Regards,</p>
<p>xx</p>
</body></html>
"""
    html = html.format(table=tabulate(databib, headers=colsbib ,tablefmt="html"))
    msg = MIMEMultipart("alternative", None, [MIMEText(html,'html')])
    msg['From'] = email_user
    msg['To'] = ",".join(email_send)
    msg['Subject'] = 'xxx report '+''+str(now.year)+"/"+str(now.month)+"/"+str(now.day)+""+str(now.hour)+":"+str(now.minute)
    text = msg.as_string()
    server = smtplib.SMTP('smtpserver',25)
    print("sent to ",email_send)
    server.sendmail(email_user,email_send,text)
    server.quit()

sendmail(databib,colsbib)


Viewing all articles
Browse latest Browse all 29929


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>