import smtplib from email.mime.text import MIMEText from email.utils import formataddr def mail(user): ret = True try: msg = MIMEText('老板,来份宫保菊花炒豆腐!!!!!!', 'plain', 'utf-8') msg['From'] = formataddr(["bbb",'25040@qq.com']) msg['To'] = formataddr(["走人",'25040@qq.com']) msg['Subject'] = "主题" server = smtplib.SMTP("smtp.126.com", 25) server.login("hu_User@126.com", "password") server.sendmail('hu_User@126.com', [user,], msg.as_string()) server.quit() except Exception: ret = False return ret #ret = mail('25040@qq.com') ret = mail('25040@qq.com') # print(ret) if ret: print("发送成功!") else: print("发送失败!")