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

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 png
SITE_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')])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值