flask email service学习笔记-html+图片(补充)

来源:互联网 发布:正版天虹打带软件下载 编辑:程序博客网 时间:2024/06/01 09:53

flask email service学习笔记-html+图片(补充)

上篇学习笔记的发送邮件中html正文中的图片是采用在html里面使用base64直接编码图片的方式发送的。
后来发现网易163的企业邮箱不支持这种内嵌的方式。
这里换一种更方便一些的方式。cid:imageName的方式。

视频分享到youtube上了。
https://youtu.be/dS6UVMQaPCI
优酷链接
http://v.youku.com/v_show/id_XMzAyNTk1MzcwOA==.html?f=50944544
GIT地址
https://github.com/aslucky/mailService.git
html模板

<body>    <header></header>    <img height="120" width="343" style="text-align:center;margin-left:8%" src="cid:invoice" alt="增值税电子普通发票"/>    <div>        <p>尊敬的用户,您好:</p>        <p><strong>您申请的电子发票已投递成功</strong>,请查收。<br>如您对发票信息有疑问请您联系商家或致电<span>400-xxx-xxxx</span></p>        <p>xx电子发票服务</p>    </div></body>

代码修改

# add html content pngSITE_ROOT = os.path.realpath(os.path.dirname(__file__))imgPath = os.path.join(SITE_ROOT, "templates", "invoice.png")with open(imgPath, 'rb') as fp: msg.attach(filename=imgPath, data=fp.read(),            content_type='application/octet-stream', disposition='inline',            headers=[('Content-ID', 'invoice')])
原创粉丝点击