# -*- coding:utf-8 -*- import smtplib from email.mime.text import MIMEText sender = '你的发送邮件' my_pass= '你的邮件登录授权码' receiver='你的接收邮件' def mail(): ret = True try: content = "正文" print(content) msg = MIMEText(content, 'plain', 'utf-8') #这里的plain表示发送的是普通文本,改成html即可在content定义html代码发送网页了。。不信你试一下。 msg['From'] = sender msg['To']=receiver msg['Subject'] = "邮件主题" server = smtplib.SMTP("发送方的smtp服务器") server.login(sender, my_pass) server.sendmail(sender, receiver, msg.as_string()) server.quit() except Exception as e: ret = False print(e) return ret ret = mail() #执行mail函数并把结果复制给ret if ret: print("邮件发送成功") else: print("邮件发送失败")
参考资料:http://soul455879510.blog.51cto.com/6180012/1893579 python搜集电脑信息发送