1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import smtplib from email.mime.multipart import MIMEMultipart from email.header import Header from email.mime.text import MIMEText from email.mime.image import MIMEImage
connect = smtplib.SMTP_SSL('smtp.qq.com',465) connect.login('QQ号@qq.com','授权码')
email = MIMEMultipart()
email['Subject'] = Header('第二次邮件发送带附件','utf-8').encode() email['To'] = 'QQ号@qq.com' email['From'] = 'QQ号@qq.com <QQ号@qq.com>'
text = MIMEText('照片在附件中,请注意查收','plain','utf-8') email.attach(text)
image_data = open('image/小猫.jpg', 'rb').read()
image = MIMEImage(image_data)
image["Content-Disposition"] = 'attachment;filename="cat.jpg"'
email.attach(image)
file_data1 = open('image/2021年“专升本”学生收费公示栏.xls',"rb").read() file1 = MIMEText('file_data1', 'base64', 'utf-8') file1['Content-Disposition'] = ' attachment; filename="a.xls"' email.attach(file1)
file_data2 = open('image/邱少云烈士纪念馆.pptx','rb').read() file2 = MIMEText('file_data1', 'base64', 'utf-8') file2['Content-Disposition'] = ' attachment; filename= "b.pptx"' email.attach(file2)
connect.sendmail('QQ号@qq.com','QQ号@qq.com',email.as_string()) connect.quit()
|