files=os.listdir("./1月10")
file_att=[]
x=0
for file in files:
if '日出' in file:
receivers = ‘@qq.com' #收件人的邮箱
subject = '日出' #主题
#初始化信息对象
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receivers
msg.attach(MIMEText('证券','plain','utf-8'))
#构造附件1,传送当前目录下文件
file_att[x] = MIMEText(open(f'./1月10/{file}','rb').read(),'base64','utf-8') # rb以二进制方式读取
file_att[x]["Content-Disposition"] = f'attachment; filename = "{file}"'
#将附件添加到MIMEMultipart中
msg.attach(file_att[x])
x=x+1
try:
s.sendmail(sender,receivers,msg.as_string())
print('发送成功')
except Exception:
print('发送失败')