Python3.3 邮件发送 含附件(各种类型文件)
来源:互联网 发布:python 定义类 编辑:程序博客网 时间:2024/06/05 15:27
1、廖雪峰教程代码会出现此种错误:
smtplib.SMTPServerDisconnected: please run connect() first,弃用
2、TypeError: getsockaddrarg: AF_INET6 address must be tuple, not str
服务器地址类型设定为元组
3、UnicodeEncodeError: ‘utf-8’ codec can’t encode character ‘\udcc9’ in position 0: surrogates not allowed
有些采用读取附件内容然后再发送附件,读取附件中中文内容错误,utf-8 和 gbk均无效
可用程序代码:
#!/usr/bin/python# -*- coding: UTF-8 -*-import smtplibimport email.mime.multipartimport email.mime.textfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.mime.application import MIMEApplicationdef send_email(smtpHost, sendAddr, password, recipientAddrs, subject='', content=''): msg = email.mime.multipart.MIMEMultipart() msg['from'] = sendAddr msg['to'] = recipientAddrs msg['subject'] = subject content = content txt = email.mime.text.MIMEText(content, 'plain', 'utf-8') msg.attach(txt) # 添加附件,传送D:/软件/yasuo.rar文件 part = MIMEApplication(open('D:/软件/yasuo.rar','rb').read()) part.add_header('Content-Disposition', 'attachment', filename="yasuo.rar") msg.attach(part) smtp = smtplib.SMTP() smtp.connect(smtpHost, '25') smtp.login(sendAddr, password) smtp.sendmail(sendAddr, recipientAddrs, str(msg)) print("发送成功!") smtp.quit()try: subject = 'Python 测试邮件' content = '这是一封来自 Python 编写的测试邮件。' send_email('xxsmtp.xxx.com.cn', 'fish@xxx.com.cn', '123456', 'fish@xxx.com.cn', subject, content)except Exception as err: print(err)
阅读全文
0 0
- Python3.3 邮件发送 含附件(各种类型文件)
- Python3.4 邮件发送(含带中文附件)
- 关于php发送邮件(含附件)
- python发送邮件(含附件)
- JAVA发送邮件Demo(含附件)
- Python3:定时发送邮件(带附件)
- 飘逸的python - 发送带各种类型附件的邮件
- 利用Java发送邮件(含附件)的例子
- JavaMail发送邮件(含附件)的例子
- JavaMail发送邮件(含附件)的例子
- Python3发送邮件(三)(附件)(qq)
- busybox sendmail发送邮件(含附件)
- springboot集成JMS含附件邮件发送
- 怎样在ASP.NET中发送邮件(含附件)
- c#.net 下的邮件发送(含附件)
- c#.net 下的邮件发送(含附件)
- c#.net 下的邮件发送(含附件)
- c#.net 下的邮件发送(含附件)
- 【sdoi2013】直径
- spring gradle 更新依赖导致的依赖冲突
- 2017北京icpc online Matrix dp
- Java-Collection源码分析(十三)——TreeMap
- 第二阶段 HTML5基础
- Python3.3 邮件发送 含附件(各种类型文件)
- angular-cli 安装与使用
- linux下ftp服务器的安装与登录
- 程序和软件有何不同
- Arrays.asList()返回的List不能add和remove
- ZooKeeper简介
- Spring MVC 中的DispatcherServlet文件与Controller类中可以使用的注解
- 洛谷1130红牌
- BZOJ1083: [SCOI2005]繁忙的都市