”’
Python 发送电子邮件
参考借鉴了http://www.cnblogs.com/xiaowuyi/archive/2012/03/17/2404015.html
在此致谢
”’
#coding=gbk import smtplib import time from email.mime.text import MIMEText def sendMail(sub, content): mailRecv = "wzhi1997@qq.com" mailHost = "smtp.yeah.net:25" mailUser = "ourauc@yeah.net" mailPass = "12345@#$%^" sender = "ourauc <" + mailUser + ">" recver = "wzhi1997 <" + mailRecv + ">" msg = MIMEText(content, _subtype = 'plain', _charset = 'gb2312') msg['Subject'] = sub msg['From'] = sender msg['To'] = recver try: server = smtplib.SMTP() server.connect(mailHost) time.sleep(1) print '[+] connected successfully' server.ehlo("ourauc") time.sleep(1) print '[+] say hello to server' server.login(mailUser, mailPass) time.sleep(1) print '[+] authentification successfully' server.sendmail(sender, recver, msg.as_string()) time.sleep(1) print '[+] sending...' server.close() return True except Exception, e: print str(e) return False if __name__ == '__main__': sub = "成功" content = """Here ia a piece of news for you. The information has been detected, please chk it out at your convenience.""" if sendMail(sub, content): print "[+] mail has been delivered" else: print "[-] something was wrong..."
”’
快开学了,死期就要来了
佛祖保佑!
”’