Ich versuche diesen Code auszuführen, um ein Excel-Blatt als Anhang einer E-Mail zu senden. Ich kann mit smtplib normale E-Mails senden, aber das MIMEMultipart funktioniert nicht. Ich erhalte die [Attribute: ‚Liste‘ Objekt hat kein Attribut ‚kodieren‘] FehlerKann mir jemand sagen, warum ich den Fehler bekomme [AttributeError: 'list' Objekt hat kein Attribut 'encode']
import smtplib, ssl
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import encoders
fromaddr = ['Email']
sendto = ['Email']
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = sendto
msg['Subject'] = 'This is cool'
body = "this is the body of the text message"
msg.attach(MIMEText(body, 'plain'))
filename = 'Work.xlsx'
attachment = open('/home/mark/Work.xlsx', 'rb')
part = MIMEBase('application', "octet-stream")
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename= %s' % filename)
msg.attach(part)
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login('email', 'password')
text = msg.as_string()
smtpObj.sendmail(fromaddr, sendto , text)
smtpObj.quit()
Ich verwende Python 3.4.3 ob das einen Unterschied könnte Beleuchtungs – Mark
einschließlich der gesamten Rückverfolgungs macht, aber ich denke, @ Kevin richtig ist. –