""" author:少校 create Time:2025/2/24 10:27 越努力越幸运 """ from smtplib import SMTP_SSL from email.mime.multipart import MIMEMultipart #邮件类 from email.header import Header #邮件主题 from email.mime.text import MIMEText #正文类 connect = SMTP_SSL("smtp.qq.com","465") connect.login("85444652@qq.com","eueysxwzzfncbhab") mail = MIMEMultipart() mail["subject"] = Header("发送附件","utf-8").encode() mail["to"] = "99928838@qq.com" mail["from"] = "shaoxiao<85444652@qq.com>" text = MIMEText("详细内容请下载附件","plain","utf-8") mail.attach(text) #=======================准备附件======================= #1.打开需要作为附件发送的文件 file_data1 = open("files/smtplib邮件自动发送.pdf","rb").read() #2.创建附件文件对应的text对象 a1 = MIMEText(file_data1,"base64","utf-8") #3.设置附件信息 #filename后面不能出现中文 a1["Content-Disposition"] = "attachment; filename='smtplib.pdf'" #4.添加附件到邮件中 mail.attach(a1) #===================================================== #发送邮件 connect.sendmail("85444652@qq.com","99928838@qq.com",mail.as_string()) connect.quit()
02.发送附件邮件
本节1022字2025-02-24 17:33:10