代码拉取完成,页面将自动刷新
import smtplib
from email.header import Header
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
smtpserver = "smtp.qq.com"
smtpport = 465
from_mail = "3312219338@qq.com"
to_mail = ["602481366@qq.com"]
password = "gbkvilmywqjochgi" # 16位授权码
msg = MIMEMultipart('related')
# 邮件主题
subject_content = """Python邮件测试"""
# 设置发送者,注意严格遵守格式,里面邮箱为发件人邮箱
msg["From"] = "sender_name<3312219338@qq.com>"
# 设置接受者,注意严格遵守格式,里面邮箱为接受者邮箱
msg["To"] = "receiver_1_name<602481366@qq.com>"
# 设置邮件主题
msg["Subject"] = Header(subject_content,'utf-8')
# 二进制读取图片
image_data = open(r'./png/2020_05_13_21_43_10.png','rb')
# 设置读取获取的二进制数据
message_image = MIMEImage(image_data.read())
message_image["Content-Type"] = 'application/octet-stream'
message_image["Content-Disposition"] = 'attachment;filename="2020_05_13_21_43_10.png"'
# 关闭刚才打开的文件
image_data.close()
# 添加图片文件到邮件信息当中去
msg.attach(message_image)
try:
smtp = smtplib.SMTP_SSL(smtpserver, smtpport)
smtp.login(from_mail, password)
smtp.sendmail(from_mail, to_mail, msg.as_string())
except(smtplib.SMTPException) as e:
print(e.message)
finally:
smtp.quit()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。