python发送邮件
来源:互联网 发布:新疆如何绕过网络管制 编辑:程序博客网 时间:2024/06/07 06:24
1.使用模块:smtplib模块
2.代码示例如下:
import smtplibdef send_mail(request): msg = MIMEMultipart() if request.method == "POST": project = request.POST["project"] address = request.POST["address"] exampleInputFile = request.FILES.get("exampleInputFile", "") filename = exampleInputFile.name.encode('gb2312') file_url = filename file_obj = open(file_url, "wb") for chunck in exampleInputFile.chunks(): file_obj.write(chunck) file_obj.close() text = request.POST["text"] txt = MIMEText(text, 'plain', 'utf-8') msg.attach(txt) # 构造附件 if exampleInputFile: att1 = MIMEText(open(file_url, 'rb').read(), 'base64', 'utf-8') att1["Content-Type"] = 'application/octet-stream' att1["Content-Disposition"] = "attachment;filename='%s'" % filename msg.attach(att1) # 加邮件头 msg['to'] = address msg['from'] = "发件人" msg['subject'] = project # 发送邮件 try: server = smtplib.SMTP() server.connect('smtp.163.com') server.starttls() server.login("用户名", "密码") server.sendmail(msg['from'], msg['to'], msg.as_string()) server.quit() response.write("发送成功!") return response except: response.write("发送失败!") return response
1 0
- 用Python发送邮件
- Python 发送邮件
- python 邮件发送
- 使用PYTHON发送邮件
- python邮件发送
- python发送邮件程序
- python: 发送邮件
- python发送邮件
- python smtp发送邮件
- python 发送邮件实例
- python发送各类邮件
- 用Python发送邮件
- 用Python发送邮件
- python 发送邮件实例
- Python发送邮件测试
- python发送邮件
- python发送邮件
- python发送邮件
- AndroidStudio 快捷使用
- MySQL命令行导出数据库
- 第十六周上机实践项目2(2):阅读程序
- Single Number
- Ubuntu14.04 LTS 下安装IntelliJ IDEA问题小结
- python发送邮件
- 运算符重载的函数(2)
- USACO 2010 Mar Gold 1.Great Cow Gathering 树形dp
- JS对象
- 第十六周上机实践项目3(1):阅读程序
- Mybits Demo
- Android开发教程(九)ProgressBar
- 4-1编程挑战
- Vijos-1243 生产产品 (DP单调队列优化)