Python利用QQ郵箱發(fā)送郵件的實(shí)現(xiàn)方法(
2017-07-03 08:17:23
17218
Python2.7
#!/usr/bin/env python2.7
# -*- coding=utf-8 -*-
import smtplib
from email.mime.text import MIMEText
_user = "648613081@qq.com"
_pwd = "這里改成你的授權(quán)碼"
_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 "發(fā)送成功"
except s.smtplib.SMTPException, e:
print "發(fā)送失敗"
Python3.6
#!/usr/bin/env python3.6
# -*- coding=utf-8 -*-
import smtplib
from email.mime.text import MIMEText
_user = "648613081@qq.com"
_pwd = "這里改成你的授權(quán)碼"
_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 ("發(fā)送成功")
except (s.smtplib.SMTPException, e):
print ("發(fā)送失敗")
會(huì)員登錄
賬號(hào)登錄還沒(méi)有賬號(hào)?立即注冊(cè)