# coding=utf-8"""发送邮件"""import smtplibfrom email.mime.text import MIMETextfrom email.header import Headerdef send_mail(content=""): print("send_mail") smtphost = 'smtp.exmail.qq.com' # smtp服务器 port = 465 # smtp服务器端口 sender = "xxxx@xx.com" # 发件人邮箱 pwd = "xxxxx" # 邮箱密码 receivers = ['xxx@xx.cn', 'xxx@xxxcn', 'xxxxx@qq.com'] # 收件人邮箱 subject = "幸运开学季脚本" # 主题 content = content or "***" msg = MIMEText(content, 'plain', 'utf-8') # 参数分别是邮件内容、文本格式、编码 msg['from'] = Header(sender) # 谁发 msg['to'] = Header("lucky_2019") # 发给谁 msg['subject'] = Header(subject) # 邮件主题 try: smtpObj = smtplib.SMTP_SSL(smtphost, port) # SSL加密 smtpObj.login(sender, pwd) smtpObj.sendmail(sender, receivers, msg.as_string()) print("send mail successfully") except smtplib.SMTPException as e: print(e) return 1
def run(): print('开始执行') while True: try: data_list = award_list() action_award(data_list) except Exception as e: print(e) msg = f"2019开学季-教师或学生脚本处理报错, 循环退出了 error is {e}" print(msg) mail(msg) continueif __name__ == "__main__": run()