Python(2.7.x)使用SMTP发送邮件的简单示例
来源:互联网 发布:arm编程 编辑:程序博客网 时间:2024/05/17 06:23
1. 发送一封简单的邮件:
2. 发送带附件的邮件:
# encoding: utf-8import smtplibsender = "test@163.com"receivers = ["temp@qq.com"]message = """From: test <test@163.com>To: temp <temp@qq.com>Subject: 测试邮件这是一封测试邮件。"""try:smtpObj = smtplib.SMTP()smtpObj.connect("smtp.163.com", "25") state = smtpObj.login("test@163.com", "123456")if state[0] == 235:smtpObj.sendmail(sender, receivers, message)print "邮件发送成功"smtpObj.quit()except smtplib.SMTPException, e:print str(e)
2. 发送带附件的邮件:
# encoding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartmsg = MIMEMultipart()msg["from"] = "test@163.com"msg["to"] = "temp@qq.com"msg["subject"] = u"测试邮件"txt = MIMEText(u"这是一封带附件的测试邮件。", "plain", "utf-8") msg.attach(txt)# 构造附件att = MIMEText(open(u"temp.zip", "rb").read(), "base64", "utf-8")att["Content-Type"] = "application/octet-stream"att["Content-Disposition"] = "attachment; filename='temp.zip'"msg.attach(att)try:smtpObj = smtplib.SMTP()smtpObj.connect("smtp.163.com", "25") state = smtpObj.login("test@163.com", "123456")if state[0] == 235:smtpObj.sendmail(msg["from"], msg["to"], msg.as_string())print u"邮件发送成功"smtpObj.quit()except smtplib.SMTPException, e:print str(e)
0 0
- Python(2.7.x)使用SMTP发送邮件的简单示例
- 使用python的smtp模块发送邮件
- python使用smtp发送邮件
- Python使用SMTP发送邮件
- Python -- 使用SMTP发送邮件
- Python 使用smtp发送邮件
- Python使用SMTP发送邮件
- python的smtp邮件发送
- C++ 使用smtp协议发送邮件的简单实现
- python发送邮件简单示例
- python使用smtp库发送邮件
- python 使用smtp发送群邮件
- Python使用SMTP自动发送邮件
- Python使用smtp协议发送邮件
- python smtp发送邮件
- python smtp发送邮件
- Python SMTP发送邮件
- Python SMTP发送邮件
- 机房收费 之 Excel导出
- Longest Substring Without Repeating Characters
- shell中流的重定向
- 可以用下面的方法让你的大脑就范
- Eclipse 建立一个简单地JAVA程序
- Python(2.7.x)使用SMTP发送邮件的简单示例
- Linux内核I2C子系统驱动(一)
- 摘录的些许概念__WinFX
- Linux---makefile
- python获取绑定的IP,并动态指定出口IP
- iOS中 Socket的使用
- hdu 1501 Zipper
- 【Python基础学习篇】Python控制语句
- 插板法的应用