1 def sendmail(): 2 import smtplib 3 from email.mime.text import MIMEText 4 from email.utils import formataddr 5 6 msg = MIMEText('邮件内容','plain','utf-8') 7 msg['From'] = formataddr(['bob','liangml0418@163.com']) 8 msg['To'] = formataddr(["走人",'1729562020@qq.com']) 9 msg['Subject'] = '主题' 10 11 server = smtplib.SMTP('smtp.163.com',25) 12 server.login('liangml0418@163.com','邮箱密码') 13 server.sendmail('liangml0418@163.com',['1729232020@qq.com'],msg.as_string()) 14 server.quit() 15 16 sendmail()