Python2.7
#!/usr/bin/env python2.7#-*-coding=utf-8-*-import smtplibfrom email.mime.text Import mimetext_user = "648613081@ Qq.com "_pwd =" Change this to your authorization code "_to =" 648613081@qq.com "msg = Mimetext (" This is a mail from Python,ha ha ha ... ") msg[" Su Bject "] =" Here is the subject "msg[" from "] = _usermsg[" to "] = _totry: s = smtplib. Smtp_ssl ("smtp.qq.com", 465) S.login (_user, _pwd) s.sendmail (_user, _to, msg.as_string ()) s.quit () print "sent successfully" except S.smtplib.smtpexception, E: print "Send Failed"
Python3.6
#!/usr/bin/env python3.6#-*-coding=utf-8-*-import smtplibfrom Email.mime.text Import mimetext_user = "648613081@qq.com" _pwd = "Change here to your authorization code" _TO = "648613081@qq.com" msg = Mimetext ("This is a e-mail from Python,ha ha ha ... ") msg[" Subject "] =" Here is the subject "msg[" from "] = _usermsg[" to "] = _totry:s = Smtplib. Smtp_ssl ("smtp.qq.com", 465) S.login (_user, _pwd) s.sendmail (_user, _to, msg.as_string ()) S.quit () print ("Send To ") except (S.smtplib.smtpexception, E): Print (" Send Failed ")