# 465端口就是 server = smtplib.SMTP_SSL('smtp.qq.com', 465) print(server) # 4.登录 loginResult = server.login(sendAddress, password) print(loginResult) # (235, b'Authentication successful') 这样子的代表你登陆成功了 # 235响应成功状态码 # 构造添加附件的邮件 from email.mime.multipart import MIMEMultipart # 1定义一个可以添加正文和附件的邮件消息对象 msg = MIMEMultipart() # msg['From'] = '你的QQ号<你的QQ号@qq.com>' msg['To'] = '李鹭禧<李鹭禧@qq.com>' msg['subject'] = '班长帮帮我' from email.mime.text import MIMEText # 构建正文 content = """ 尊敬的先生: 你好! 我是你的室友小罗,请放假的时候帮我搬行李!!! """ msg.attach(MIMEText(content,'plain', 'utf-8')) # 添加正文 attachment_1 = MIMEText(open('1.jpg', 'rb').read(), 'base64', 'utf-8') attachment_1['Content-Type'] = 'application/octet-stream' attachment_1['Content-Disposition'] = 'attachment;filename="1.jpg"' msg.attach(attachment_1) attachment_2 = MIMEText(open('2.jpg', 'rb').read(), 'base64', 'utf-8') attachment_2['Content-Type'] = 'application/octet-stream' attachment_2['Content-Disposition'] = 'attachment;filename="2.jpg"' msg.attach(attachment_2) # 发送邮件 To = ['(对方QQ号)@qq.com'] server.sendmail(sendAddress, To, msg.as_string()) print('发送成功')