标签:style blog color io os 使用 sp div on
#!/usr/bin/env python # -*- coding: utf-8 -*- #导入smtplib和MIMEText import smtplib from email.MIMEText import MIMEText mail_to="XXXXXXXX@qq.com" #要发给谁 def send_mail(to_list,sub,content): #设置服务器,用户名、口令以及邮箱的后缀 mail_host="smtp.163.com" mail_user="你邮箱的账号" mail_pass="你的密码" mail_postfix="163.com" me=mail_user+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content) msg[‘Subject‘] = sub msg[‘From‘] = me msg[‘To‘] = to_list print msg try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pass) s.sendmail(me, to_list, msg.as_string()) s.close() print ‘1‘ return True except Exception, e: print ‘2‘ print str(e) return False #if __name__ == ‘__main__‘: if __name__ == ‘__main__‘: if send_mail(mail_to,"hello","this is python sent"): print "发送成功" else: print "发送失败"
可以使用,但是为了防止你的邮箱被退回,或是作为垃圾邮件,要每隔一段时间在发送。
标签:style blog color io os 使用 sp div on
原文地址:http://www.cnblogs.com/huhuuu/p/3993513.html