毁灭吧,累了,语法错误

import smtplib
from email import message
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

mailUser = "2424925871@qq.com"
mailPass = "btvlsuqhbolxdjhe"
smtpObj = smtplib.SMTP_SSL("smtp.qq.com", 465)
smtpObj.login(mailUser, mailPass)

sender = "2424925871@qq.com"
receiverDict = {"yqbc": "yequbiancheng@baicizhan.com"}
path = r"C:\Users\tianc\Pictures\SavedPictures\微信截图_20220819122601.png"

for receiver in receiverDict:
    message = MIMEMultipart()
    message["from"] = Header(f"Aries<{sender}>")
    message["Subject"] = Header(f"给夜曲的一封信")
    mailContent = MIMEText("Dear Mr.coco: Good afternoon, thank you for your company these days. I wish you a bright future and success", "plain", "utf-8")

    filePath = path + "\" + "微信截图_20220819122601.png"

with open(filePath, "rb") as imageFile:
    fileContent = imageFile.read()
    att = MIMEImage(fileContent)
    att.add_header("Content-Disposition", "attachment", filename="入门成绩单.jpg")
    message.attach(mailContent)
    message.attach(att)
    smtpObj.sendmail(sender, receiverDict[receiver], message.as_string())
    print("发送成功")

改成这样

img

img

img

建议你发邮件时这样发送附件:

# -*- coding: utf-8 -*-
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication

mail_host = 'smtp.qq.com'
port = 465
send_by = '151xxxx829@qq.com'
password = 'meoxxxxdcelxxic'
send_to = '151xxxx829@qq.com'


msg = MIMEMultipart() # 创建一个带附件的实例
msg["Subject"] = "Tomorrow is another day"
msg["From"] = send_by
msg["To"] = ','.join(send_to)

# ---文字部分---
part = MIMEText("请查收,谢谢!")
msg.attach(part)

# ---附件部分---
part = MIMEApplication(open('lessontable.xls', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename="lessontable.xls")
msg.attach(part)

try:
    # 要注意位置参数和关键字参数啊啊
    smpt = smtplib.SMTP_SSL(mail_host, port, 'utf-8')
    smpt.login(send_by, password)
    smpt.sendmail(send_by, send_to, msg.as_string())
    # print(message.as_string)
    smpt.quit()
    print("发送成功")
except:
    print("发送失败")