Sending emails with "if" - Python -


i'm trying figure out i'm going wrong code below:

for row in cursor.execute("select * orcam anomes=?", cdate):     try:        percfor = (row.vr_forecast / 100) * 90     except typeerror:        percfor = row.vr_forecast     if row.vr_real > percfor , row.vr_forecast > 0:        print(row.ccusto, row.grupo, row.anomes)        try:            body = """<html><body> <font face="calibri" size="3" color = "black"> alertamos que os gastos com o cc """ + row.ccusto + """ grupo """ + row.grupo + """, sob sua responsabilidade, excedeu 90% previsto no forecast para o mes """ + cdate + """ conforme abaixo: <br> <b>- previsto:</b> """ + str(row.vr_forecast) + """ <br> <b>- real:</b> """ + str(row.vr_real) +  """ </body></html>"""            msg.attach(mimetext(body, 'html'))            server = smtplib.smtp('server',25)            server.starttls()            server.sendmail(emailfrom, emailto.split(';'), msg.as_string())            server.quit()            print "successfully sent email!"        except exception:            print "error: unable send email"            server.quit() 

output:

(u'0100', u'0590', u'201709') sent email! (u'0100', u'0633', u'201709') sent email! (u'0100', u'0759', u'201709') sent email! 

the first line, it's select getting data current month/year. then, each line compare if value real(vr_real) greater "percfor". if so, send email.

the problem it's repeating , adding attachments of emails should send. seems need clear "body" string before send new emails i'm not sure whether code logic ok.

as can see in "output" it's going line line third email send same email first adding attach values third , second.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -