1 Star 0 Fork 0

paperballin/ScreenCut

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
SendEmail.py 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
paperballin 提交于 2020-06-03 15:58 . Create Test
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/paperballin/ScreenCut.git
git@gitee.com:paperballin/ScreenCut.git
paperballin
ScreenCut
ScreenCut
master

搜索帮助