问题描述
有人可以帮我吗?
我想为python中的电子邮件发件人附加一个excel文件,但每次都会出错。我在网上看了看,到处都说它像在我的代码中一样。有人可以告诉我怎么了
非常感谢您
message = MIMEMultipart()
message['Subject'] = 'Maandelijks rapport'
message['To'] = receiver_email
message['From'] = sender_email
message.attach(MIMEText('In de bijlage vind je het maandrapport terug!'))
part = MIMEBase('application',"octet-stream")
part.set_payload(open('test.xls',"rb").read())
encoders.encode_base64(part)
part.add_header('Content-Desposition','attachment; filename="test.xls"')
message.attach(part)
#send the email
with smtplib.SMTP_SSL("smtp.gmail.com",465) as smtp:
smtp.login(sender_email,password)
print('connecting with smtp server...')
smtp.login(sender_email,password)
smtp.sendmail(sender_email,receiver_email,message.as_string())
print('connection succeed!')
print('email has been sent!')
smtp.quit()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)