import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart #多媒体处理模块
from email.header import Header
mail_host = "smtp.qq.com"
mail_user = "888888@qq.com"
mail_pass = "*******" #授权码
sender = "888888@qq.com"
receiver = ["888888@qq.com"]
textContent = MIMEText('这个邮件里面展示了我用四行代码给图片加一个滤镜的功能','plain','utf-8')
textContent['From'] = Header("夜曲编程",'utf-8')
textContent['To'] = Header("测试",'utf-8')
imageFile = './/image//01.jpg'
imageAttachment = MIMEImage(open(imageFile,'rb').read(),'jpeg')
imageAttachment.add_header('Content-Disposition','attachment',filename=imageFile)
imageFile2 = '郭麒麟.jpg'
imageAttachment2 = MIMEImage(open(imageFile2,'rb').read(),'jpeg')
imageAttachment2.add_header('Content-Disposition','attachment',filename=imageFile2)
message = MIMEMultipart()
message.attach(textContent)
message.attach(imageAttachment)
message.attach(imageAttachment2)
subject = '夜曲编程pythonSMTP邮件测试'
message['Subject'] = Header(subject,'utf-8')
smtpObj = smtplib.SMTP_SSL(mail_host)
smtpObj.connect(mail_host,465)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender,receiver,message.as_string())
print("发送邮件成功")
来源:CSDN
作者:慢慢学编程
链接:https://blog.csdn.net/weixin_40492102/article/details/103706517