Why can not I use Array to add inside a variable of type MIMEText (msg = MIMEText (body, 'html'))?
I explain:
for row in cursor.fetchall():
for owner in cursor.execute("select * from orcam where Ccusto=? and anomes=?", row.Ccusto, cdate):
print owner
if owner.Vr_real > percFor and owner.Vr_Forecast > 0:
print(owner.Ccusto, owner.Grupo, owner.Anomes)
body.append("""a""")
print i
print body[i]
i = i + 1
try:
msg = MIMEText(body, 'html')
msg["From"] = emailfrom
msg["Subject"] = "XXXXXXXX"
msg["To"] = emailto
server = smtplib.SMTP('server',25)
server.starttls()
server.sendmail(emailfrom, emailto.split(';'), msg.as_string())
server.quit()
print "Successfully sent email!"
server.close()
except Exception:
print "Error: unable to send email"
server.close()
server.quit()
My intention is to make every time that the "if" is true it will add inside the body of an email. So I tried to do it in array form, it even adds the messages inside the array array, but at the time of adding inside MIMEText it brings me the error.
['a', 'a', 'a']
Error: unable to send email
Traceback (most recent call last):
File ".\orcam_1.py", line 71, in <module>
server.close()
AttributeError: 'str' object has no attribute 'close'
Is there any other way to add messages in the body of the email, as you enter the IF?