基于python的extract_msg模块提取outlook邮箱保存的msg⽂件中的附件
笔者保存了⼀些outlook邮箱中保存的⼀些msg格式的邮件⽂件,现需要将其中的附件提取出来,
当然直接在outlook中就可以另存附件,但outlook默认是不⽀持批量提取邮件中的附件的
思考过⼏种⽅案,其中之⼀就是使⽤python编程语⾔下的extract_msg模块,记录如下
1、安装extract_msg模块pip install extract-msg,笔者写此随笔时,最新版本为extract-msg 0.27.4
陶瓷彩绘2、安装后,最简单的使⽤,直接在命令⾏⼀条命令,即可将msg中的⽂件解压到当前⽬录下的⼀个⼦⽬录中(⽬录名与邮件信息有关)
#会在当前⽬录下,⽣成⼀个⽬录,然后将msg邮件⽂件中的附件和解压到其中
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:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 422, in named
return lf.__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:\Urs\QQ5201351\Desktop\mail\test\test.py", line 5, in <module>
msg = extract_msg.Message("Important_msg_from_qq5201351.msg")
File "C:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\message.py", line 28, in__init__
MessageBa.__init__(lf, path, prefix, attachmentClass, filename, delayAttachments, overrideEncoding)
黄蜻
File "C:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\message_ba.py", line 61, in__init__
lf.named四时田园杂兴其二
File "C:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 424, in named
lf.__namedProperties = Named(lf)
File "C:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\named.py", line 63, in__init__
白带多是什么原因
lf.__properties.append(StringNamedProperty(entry, names[entry['id']], msg._getTypedData(streamID)) if entry['pkind'] == constants.STRING_NAMED el NumericalNamedProperty(entry, msg._getTypedData(streamID)))
File "C:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 177, in _getTypedData
found, result = lf._getTypedStream('__substg1.0_' + id, prefix, _type)
File "C:\Urs\QQ5201351\AppData\Local\Programs\Python\Python37\lib\site-packages\extract_msg\msg.py", line 246, in _getTypedStream
中药饭前吃还是饭后吃
rai 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, plea create an issue labled "NotImplementedError: _getT 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, plea create an issue labled "NotImplementedError: _getTyped