Search code examples
pythonhtml-email

python email update content


I have a snippet of code, in for loop to send email updating the email content for each iteration in for loop. but the email body doesn't get update . please help me.

I've tried adding del message but no luck

for i in range(0,3) :
    data = [[i,i,i,i,i,]]+data
    print(data)
    text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))
    html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))
    message = MIMEMultipart(
        "alternative", None, [MIMEText(text), MIMEText(html,'html')])
    #message.attach(MIMEText(html,'html'))i
    sub_time = datetime.datetime.now()+datetime.timedelta(hours=5,minutes=30)
    sub = "Time - "+str(sub_time.hour)+":"+str(sub_time.second)

    message['Subject'] = sub
    message['From'] = me
    message['To'] = you
    server.login(me, password)

    server.sendmail(me, you, message.as_string())

here in mail, I get 0,0,0,0,0+data for all 3 iterations.


Solution

  • ##text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))
    
    text = format(tabulate(data, headers="firstrow", tablefmt="grid"))
    ##html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))
    
    html = format(tabulate(data, headers="firstrow", tablefmt="html"))