最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python利用QQ邮箱发送邮件的实现方法
时间:2017-06-12 编辑:简简单单 来源:一聚教程网
废话不多说,直接上代码
Python2.7
代码如下 | 复制代码 |
#!/usr/bin/env python2.7 # -*- coding=utf-8 -*-
importsmtplib fromemail.mime.textimportMIMEText _user="648613081@qq.com" _pwd="这里改成你的授权码" _to ="648613081@qq.com"
msg=MIMEText("this is a email from python,ha ha ha ...") msg["Subject"]="这里是主题" msg["From"]=_user msg["To"]=_to
try: s=smtplib.SMTP_SSL("smtp.qq.com",465) s.login(_user, _pwd) s.sendmail(_user, _to, msg.as_string()) s.quit() print"发送成功" excepts.smtplib.SMTPException, e: print"发送失败" |
Python3.6
代码如下 | 复制代码 |
#!/usr/bin/env python3.6 # -*- coding=utf-8 -*-
importsmtplib fromemail.mime.textimportMIMEText _user="648613081@qq.com" _pwd="这里改成你的授权码" _to ="648613081@qq.com"
msg=MIMEText("this is a email from python,ha ha ha ...") msg["Subject"]="这里是主题" msg["From"]=_user msg["To"]=_to
try: s=smtplib.SMTP_SSL("smtp.qq.com",465) s.login(_user, _pwd) s.sendmail(_user, _to, msg.as_string()) s.quit() print("发送成功") except(s.smtplib.SMTPException, e): print("发送失败") |
-
下一个: python的私有公有属性
相关文章
- qq邮箱已发送的邮件怎么撤回? 01-28
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24