html当作附件发送,MIME以HTML文件作为附件发送电子邮件?
发布日期:2022-02-18 13:08:19 浏览次数:12 分类:技术文章

本文共 901 字,大约阅读时间需要 3 分钟。

在标准文档中,请参见第三个使用模块email的示例# Import smtplib for the actual sending function

import smtplib

# And imghdr to find the types of our images

import imghdr

# Here are the email package modules we'll need

from email.message import EmailMessage

# Create the container email message.

msg = EmailMessage()

msg['Subject'] = 'Our family reunion'

# me == the sender's email address

# family = the list of all recipients' email addresses

msg['From'] = me

msg['To'] = ', '.join(family)

msg.preamble = 'Our family reunion'

# Open the files in binary mode. Use imghdr to figure out the

# MIME subtype for each specific image.

for file in pngfiles:

with open(file, 'rb') as fp:

img_data = fp.read()

msg.add_attachment(img_data, maintype='image',

subtype=imghdr.what(None, img_data))

# Send the email via our own SMTP server.

with smtplib.SMTP('localhost') as s:

s.send_message(msg)

编辑:对于其他文件,您可以得到maintype,subtype

^{pr2}$

转载地址:https://blog.csdn.net/weixin_28871097/article/details/117865357 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:广东海洋大学数学与计算机学院校友会,数学与计算机学院召开2020级研究生入学教育会...
下一篇:主流家用计算机,年终聊装机 主流家用电脑怎么选CPU?

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年03月06日 15时30分00秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

php ajax上传图片过大500错误,javascript – JQuery AJAX文件上传错误500 2019-04-21
matlab 图中的legend,matlab中legend加图示命令的使用 2019-04-21
PHP exec xargs 不执行,Linux中的xargs命令及示例 2019-04-21
php 枚举cookie内容,php设置和获取cookie 2019-04-21
单防区扩展模块怎么用_AB罗克韦尔自动化Micro800 扩展 I/O模块型号及功能介绍 2019-04-21
java矩阵类_Java泛型——泛型矩阵类 2019-04-21
java车牌正则表达式_车牌正则表达式 2019-04-21
wordpress4.9.4 mysql_WordPress 将不再支持 PHP4 和 MySQL 4 2019-04-21
安卓是用java语言写的吗_android开发是用java语言吗? 2019-04-21
java 符号 t_java – 运算符”不能应用于’T’,’T’表示有界泛型类型 2019-04-21
用matlab写出信源熵,计算离散信源的熵matlab实现 2019-04-21
php表单yii2,Yii2创建表单(ActiveForm)方法详解 2019-04-21
php 程序授权机制,授权认证详细说明 2019-04-21
java 命令提示符,如何使用Java打开命令提示符并插入命令? 2019-04-21
IP/tzgm.php,LianjiaSpider/在售数量.ipynb at master · BerSerK/LianjiaSpider · GitHub 2019-04-21
linux移动文件的脚本,使用Linux脚本移动文件 2019-04-21
linux查看系统所有变量,Linux系统各指标命令 2019-04-21
linux打印机守护程序,linux下怎么编写守护程序呢? 2019-04-21
嵌入式linux 设置时间,time_clock控件应用,使用命令date -s 12:00:00手动设置时间后,时间就停住不走了,我在Ubuntu和嵌入式Linux平台都测试到了... 2019-04-21
linux 8086下编译,Ubuntu18.04/Linux下安装DosBox进行8086汇编 2019-04-21