基于python的extract_msg模块提取outlook邮箱保存的msg文件中的附件
笔者保存了一些outlook邮箱中保存的一些msg格式的邮件文件,现需要将其中的附件提取出来,
当然直接在outlook中就可以另存附件,但outlook默认是不支持批量提取邮件中的附件的
思考过几种方案,其中之一就是使用python编程语言下的extract_msg模块,记录如下
1、安装extract_msg模块 pip install extract-msg ,笔者写此随笔时,最新版本为extract-msg 0.27.4
发布于Released: Sep 3, 2020,项目说明:https://pypi.org/project/extract-msg
2、安装后,最简单的使用,直接在命令行一条命令,即可将msg中的文件解压到当前目录下的一个子目录中(目录名与邮件信息有关)
#会在当前目录下,生成一个目录,然后将msg邮件文件中的附件和message.txt解压到其中
python -m extract_msg qq_5201351.msg
3、在py文件中,可以使用如下方法只提取其中的附件(需要先创建要保存附件的目录):
import extract_msg
msg = extract_msg.Message("qq_5201351.msg")
msg_attachment = msg.attachments
if msg_attachment:
for attachment in msg_attachment:
attachment.save(customPath="./qq_5201351_dir")
++++++未解决的问题>>>>:
1、使用上面的方法对于大多数msg都能够正常提取出附件,或者邮件内容,但是笔者有的mgs提取时会报如下错误,
目录未找到解决方法, 如有找到解决方法的,欢迎下方留言,非常感谢!
Traceback (most recent call last):
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 422, in named
return self.__namedProperties
AttributeError: 'Message' object has no attribute '_MSGFile__namedProperties' During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "C:\Users\QQ5201351\Desktop\mail\test\test.py", line 5, in <module>
msg = extract_msg.Message("Important_msg_from_qq5201351.msg")
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\message.py", line 28, in __init__
MessageBase.__init__(self, path, prefix, attachmentClass, filename, delayAttachments, overrideEncoding)
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\message_base.py", line 61, in __init__
self.named
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 424, in named
self.__namedProperties = Named(self)
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\named.py", line 63, in __init__
self.__properties.append(StringNamedProperty(entry, names[entry['id']], msg._getTypedData(streamID)) if entry['pkind'] == constants.STRING_NAMED else NumericalNamedProperty(entry, msg._getTypedData(streamID)))
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 177, in _getTypedData
found, result = self._getTypedStream('__substg1.0_' + id, prefix, _type)
File "C:\Users\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 246, in _getTypedStream
raise NotImplementedError('The stream specified is of type {}. We don\'t currently understand exactly how this type works. If it is mandatory that you have the contents of this stream, please create an issue labled "NotImplementedError: _getTypedStream {}".'.format(_type, _type))
NotImplementedError: The stream specified is of type 1014. We don't currently understand exactly how this type works. If it is mandatory that you have the contents of this stream, please create an issue labled "NotImplementedError: _getTypedStream 1014".
尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/13695389.html
基于python的extract_msg模块提取outlook邮箱保存的msg文件中的附件的更多相关文章
- Python:将爬取的网页数据写入Excel文件中
Python:将爬取的网页数据写入Excel文件中 通过网络爬虫爬取信息后,我们一般是将内容存入txt文件或者数据库中,也可以写入Excel文件中,这里介绍关于使用Excel文件保存爬取到的网页数据的 ...
- 提取数据表保存为XML文件
//连接数据库 SqlConnection con = new SqlConnection("server=****;database=****;uid=sa;pwd=********&qu ...
- 基于 Python 的自动文本提取:抽象法和生成法的比较
我们将现有的 提取方法(Extractive)(如LexRank,LSA,Luhn和Gensim现有的TextRank摘要模块)与含有51个文章摘要对的Opinosis数据集进行比较.我们还尝试使用T ...
- 基于Python的datetime模块和time模块源码阅读分析
目录 1 前言 2 datetime.pyi源码分步解析 2.1 头部定义源码分析 2.2 tzinfo类源码分析 2.3 date类源码分析 2.4 time类源码分析 2.5 timedelta ...
- 如何将Python对象保存在本地文件中?
Python对象的永久存储 1.使用Python的pickle模块 import pickle class A: def __init__(self,name,a): self.name=name s ...
- Python学习笔记之爬取网页保存到本地文件
爬虫的操作步骤: 爬虫三步走 爬虫第一步:使用requests获得数据: (request库需要提前安装,通过pip方式,参考之前的博文) 1.导入requests 2.使用requests.get ...
- Python学习笔记_从CSV读取数据写入Excel文件中
本示例特点: 1.读取CSV,写入Excel 2.读取CSV里具体行.具体列,具体行列的值 一.系统环境 1. OS:Win10 64位英文版 2. Python 3.7 3. 使用第三方库:csv. ...
- 基于Python的多线程模块Threading小结
步入正题前,先准备下基本知识,线程与进程的概念. 相信作为一个测试人员,如果从理论概念上来说其两者的概念或者区别,估计只会一脸蒙蔽,这里就举个例子来说明下其中的相关概念. 平安夜刚过,你是吃到了苹果还 ...
- 基于python第三方requests 模块的HTTP请求类
使用requests模块构造的下载器,首先安装第三方库requests pip install requests 1 class StrongDownload(object): def __init_ ...
随机推荐
- 第3章 Hive数据类型
第3章 Hive数据类型 3.1 基本数据类型 对于Hive的String类型相当于数据库的varchar类型,该类型是一个可变的字符串,不过它不能声明其中最多能存储多少个字符,理论上它可以存储2GB ...
- random模块python
random是用于生成随机数的,我们可以利用它随机生成数字或者选择字符串. random.random() 用于生成一个随机浮点数:range[0.0,1.0) ? 1 2 import ran ...
- 算法-排序(1)k路平衡归并与败者树
const int MaxValue=; //根据实际情况选择最大值 void kwaymerge(Element *r,int k){ int i,q; r=new Element[k]; //在败 ...
- MPI组操作
进程组的创建 MPI_Comm_Group int MPI_Comm_group( MPI_Comm comm, MPI_Group *group ); 把相同的通信子进程放到一个组内. #inclu ...
- java23种设计模式——三、工厂模式
源码在我的github和gitee中获取 工厂模式 工厂模式介绍 工厂模式是我们最常用的实例化对象模式了,是用工厂方法代替new操作的一种模式.著名的Jive论坛 ,就大量使用了工厂模式,工厂模式在J ...
- FormData格式的数据
向服务器提交的是FormData格式的数据 || 必须添加以下两个配置项 contentType:false, processData:false,
- 服务发现Eureka、zookeeper、consul
Spring Cloud为开发人员提供了工具,以快速构建分布式系统中的某些常见模式(例如,配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁,领导选举,分布式会话,群集状态). ...
- k8s部署mysql主从复制
Mysql主从 准备环境 一,准备软件 官方docker_image :Mysql5.7.28 Docker Version: 19.03.4 K8s api-version: ...
- Python 30道高频面试题及详细解答
开学啦,开学啦!周末坐地铁的时候看到很多同学推着行李箱,拎着大包小包的穿梭在人群中,哎新的一学期又开始啦,同时也意味着很多同学要准备毕业啦,尤其是准大四,准研三的同学. 今年的招聘行情并不乐观,小公司 ...
- [PyTorch 学习笔记] 4.3 优化器
本章代码: https://github.com/zhangxiann/PyTorch_Practice/blob/master/lesson4/optimizer_methods.py https: ...