Python 调用QQ邮箱发送邮件

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

####### smtp
mail_host = “smtp.qq.com”
####### sender
mail_sender = “[email protected]

mail_license = “Q29uYW4gbG92ZSBWaXZpYW4=”
Python 调用QQ邮箱发送邮件

####### reciver
mail_receivers = [“[email protected]”]

mm = MIMEMultipart(‘related’)
#######subject
subject_content = “”“Python Email demo”""
#######sender
mm[“From”] = “Conan_ft<[email protected]>”
####### reciver
mm[“To”] = “Conan_ft<[email protected]>”
#######subject
mm[“Subject”] = Header(subject_content,‘utf-8’)

####### content
body_content = “”“Hello, this is a test file, please do not reply!”""
message_text = MIMEText(body_content,“plain”,“utf-8”)
mm.attach(message_text)

####### add picture
#image_data = open(‘a.jpg’,‘rb’)
#message_image = MIMEImage(image_data.read())
#image_data.close()
#mm.attach(message_image)

#######add file
#atta = MIMEText(open(‘sample.xlsx’, ‘rb’).read(), ‘base64’, ‘utf-8’)
#atta[“Content-Disposition”] = ‘attachment; filename=“sample.xlsx”’
#mm.attach(atta)

####### structure mail
stp = smtplib.SMTP()
####### port
stp.connect(mail_host, 25)
####### set_debuglevel(1)
stp.set_debuglevel(1)
####### structure
stp.login(mail_sender,mail_license)
####### sender to str
stp.sendmail(mail_sender, mail_receivers, mm.as_string())
print(“Send Email successful”)
#Close the connection
stp.quit()