import smtplib
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
sender = '[email protected]'
password = 'uaimpajcklvecahc'
receivers = ["[email protected]", "[email protected]", "[email protected]"]
message = MIMEMultipart()
message['Subject'] = '开门,劳资是附件邮件1017'
message['From'] = sender
message['To'] = ";".join(receivers)
message.attach(MIMEText('这是Python 邮件发送测试……', 'plain', 'utf-8'))
att1 = MIMEText(open('./res/1.txt', 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment; filename="fuck.txt"'
message.attach(att1)
msgImage = MIMEImage(open('./res/meinvb.jpg', 'rb').read())
msgImage["Content-Type"] = 'application/octet-stream'
msgImage["Content-Disposition"] = 'attachment; filename="dameinv.jpg"'
message.attach(msgImage)
try:
smtpObj = smtplib.SMTP_SSL()
smtpObj.connect('smtp.qq.com', 465)
smtpObj.login(sender, password)
smtpObj.sendmail(sender, receivers, message.as_string())
smtpObj.quit()
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error: 无法发送邮件", e)