ITxiaobaibai 2020-01-03
import smtplib from email.mime.text import MIMEText subject = "标题" # 邮件的主题 content = "测试" # 邮件的内容 sender = "" # 发件人 password = "qnrwndesjxmmijce" # 刚才我们在QQ邮箱里设置的授权密码 receiver = "" # 收件人 message = MIMEText(content, "plain", "utf-8") # 内容,格式,编码格式 message["From"] = sender # 发送邮箱 message["To"] = receiver # 接收邮箱 message["Subject"] = subject # 标题 # message = ‘\n‘.join([‘From: {}‘.format(sender), ‘To: {}‘.format(receiver), ‘Subject: {}‘.format(subject), ‘‘, content]) # smtp = smtplib.SMTP() # 普通的邮件发送形式 smtp = smtplib.SMTP_SSL("smtp.qq.com", 465) # QQ邮箱的SMTP服务器(端口465或587) smtp.set_debuglevel(1) # 用set_debuglevel(1)就可以打印出和SMTP服务器交互的所有信息 smtp.login(sender, password) # 登录SMTP服务器,输入发送邮箱和密码 smtp.sendmail(sender, receiver, message.as_string()) smtp.quit() smtp.close()