import smtplibimport urllibfrom email.mime.text import MIMETextmailto_list = ["674613047@qq.com"]mail_host = "smtp.139.com" # 设置服务器mail_user = "15804066512@139.com" # 用户名mail_pass = "581388jingying@" # 口令mail_postfix = "139.com" # 发件箱的后缀def send_mail(to_list, title, content): # to_list:收件人;sub:主题;content:邮件内容 me = mail_user.split("@")[0]+ "<" + mail_user + ">" # 这里的hello可以任意设置,收到信后,将按照设置显示 msg = MIMEText(content, _subtype='html', _charset='utf-8') # 创建一个实例,这里设置为html格式邮件 msg['Subject'] = title # 设置主题 msg['From'] = me msg['To'] = ";".join(to_list) try: s = smtplib.SMTP() s.connect(mail_host) # 连接smtp服务器 s.login(mail_user, mail_pass) # 登陆服务器 s.sendmail(me, to_list, msg.as_string()) # 发送邮件 s.close() return True except Exception, e: print str(e) return Falsesend_mail(mailto_list, "邮件主题", "内容")