抄刘天斯君的脚本,不过做了些改动.
#!/usr/bin/env python #coding:utf-8 #version: 20150101 #filename: sendmail.py #在其它脚本可以使用以下两行,就可以进行邮件发送工作 #import sendmail #sendmail.sendToUser("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") import smtplib,string HOST = "邮件服务器IP/或者域名" Subject = "苗疆道士又有更新了" FROM = "1.qq.com" #如果需要发给它多个用户,可以直接使用分号隔开 TO = "[email protected]" PASS = "ssss" def sendToUser(text): BODY = string.join(( "From: %s" % FROM, "To: %s" % TO, "Subject: %s" % Subject, "", text ), "\r\n") server = smtplib.SMTP() server.connect(HOST,"25") #主机属于mynetworks网段,可以不经过密码认证发送邮件 if PASS != "": try: server.login(FROM, PASS) except smtplib.SMTPAuthenticationError, e: print "连接到邮件服务器时,身份认证不通过,密码可能有问题!!" print e server.sendmail(FROM, [TO], BODY) server.quit() #sendToUser("无言独上西楼.")