Python 发送带附件邮件客户端
来源:互联网 发布:数据自动传输的风速仪 编辑:程序博客网 时间:2024/05/20 02:24
参考自:http://blog.csdn.net/wyuan8913/article/details/6917873
想说一下坑了我不少时间的几点:
1.
from email.mime.multipart import MIMEMultipart
我猜是因为版本的问题,之前使用MIMEMultipart的import不是这么写的。一直报错。
2.
content = MIMEText(text, 'plain','utf-8')
这里的'plain' 在参考链接里写的是'text',然后也一直报错,改成这样就成功了。
3.
password=password.strip('\n')
之前写成password.strip('\n'),发现一直没有去除比较末尾的换行符,还以为是strip失灵了,蛋疼了无数时间之后才改了错。。
#! /usr/local/ActivePython-3.2/bin#coding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Headerfrom email.mime.multipart import MIMEMultipartreceiver = '*****@qq.com'subject = 'python email test'smtpserver = 'smtp.163.com'username = '*****@163.com'sender=usernamewith open('passwd.txt') as file: password = file.readline()password=password.strip('\n')msg=MIMEMultipart('alternative')msg['Subject']='test message'text='你好'content = MIMEText(text, 'plain','utf-8') msg.attach(content)#create the attachmentattfile='buptsnow.jpg' att=MIMEText(open(attfile,'rb').read(),'base64', 'utf-8')att["Content-Type"] = 'application/octet-stream'att["Content-Disposition"] = 'attachment; filename="buptsnow.jpg"'msg.attach(att)smtp = smtplib.SMTP()smtp.connect('smtp.163.com')smtp.login(username, password)smtp.sendmail(sender, receiver, msg.as_string())smtp.quit()
- Python 发送带附件邮件客户端
- python邮件发送带附件
- python+带附件发送邮件
- python发送带附件邮件
- Python 发送带 附件 邮件 脚本
- python发送带附件的邮件
- python发送邮件sendmail--smtplib【带附件】
- Python 发送带 附件 邮件 脚本
- Python发送带附件的SMTP邮件
- 使用Python发送带附件的邮件
- Python SMTP发送邮件 - 带附件
- python发送带附件的邮件
- Python 发送带附件的邮件
- Python发送带附件的邮件
- python 发送邮件(2) 带附件
- 邮件发送(带附件)
- C#发送带附件邮件
- java发送带附件邮件
- Linux之父炮轰C++:糟糕程序员的垃圾语言
- 理解WebKit和Chromium: WebKit的CSS实现
- 可变参数函数的实现
- Windows 文件系统过滤驱动开发教程 (第二版)
- invalid conversion from `const char*' to `char*' 的解决方法
- Python 发送带附件邮件客户端
- Strust框架学习
- PHP中的ob_start用法详解
- Flex for Free: Setting Up the Flex 4 SDK with Eclipse IDE
- XmlBeans使用笔记
- 锁屏状态下,看到歌手图片
- myql 删除一条记录时遇到的错误,及改正!!!!
- PDE弱形式介绍
- Asp.net如何生成html静态页面