基于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_ ...
随机推荐
- 在 Linux 中查找和删除重复文件
原文链接:https://www.linuxprobe.com/linux-FSlint.html FSlint同时具有GUI和CLI模式.因此,对于新手来说,这是一个用户友好的工具.FSlint不仅 ...
- (数据科学学习手札94)QGIS+Conda+jupyter玩转Python GIS
本文完整代码及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 QGIS随着近些年的发展,得益于其开源免费 ...
- PAT甲级真题 A1025 PAT Ranking
题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- Windows Server 2012 数据库定时备份
为了数据的安全,我们在服务器上设置了每周备份一次,下面是具体步骤: 一.在文件客户端服务器创建db_backup.cmd的Windows命令脚本.输入以下内容(直接复制可能出错,请手动输入): @ec ...
- Serializers组件详解
Serializers组件 使用背景 因为每个语言都有自己的数据类型,不同语言要想数据传输,就必须指定一种各种语言通用的数据类型,如json,xml等等 序列化器允许把像查询集和模型实例这样的复杂数据 ...
- 关于Chrome浏览器自动同步的问题
Chrome浏览器是开发者最喜欢的浏览器,没有之一,那么公司办公和在家办公的话数据需要有一致性,这个时候就用到了浏览器的自动同步的功能 因为网络的问题,谷歌账户很难登录,基本需要VPN翻墙处理之后才能 ...
- Java开发环境搭建的准备工作
Java开发环境搭建的准备工作 网络配置(修改hosts) 什么时候需要 比如我们在安装homeBrew的时候会遇到 curl: (7) Failed to connect to raw.github ...
- C++ Templates (2.2 使用Stack类模板 Use of Class Template Stack )
返回完整目录 目录 2.2 使用Stack类模板 Use of Class Template Stack 2.2 使用Stack类模板 Use of Class Template Stack 在C++ ...
- Git深入浅出使用教程:Git安装、远程控制、常用命令(全)
一.软件安装 1.先安装[Git-2.24.1.2-64-bit.exe]软件.(官网下载的很慢,可以在百度云盘下载我的) 链接:https://pan.baidu.com/s/1uoIS9DWSBp ...
- 【python开发】迈出第一步,这可能是我唯一一次的Python开发了
好久没写博了,今天就瞎唠唠吧 背景: 组内有个测试平台,是基于Python2+tornado 框架写的,之前自己维护了一套系统的UIweb自动化代码,现在需要集成进去.这很可能是自己唯一一次基于pyt ...