从Outlook邮件文件中读取内容、元数据和附件
outlook-msg的Python项目详细描述
outlook_msg
outlook_msg
是一个python库,由Hamilton Group处理
用户可以从outlook导出。在使用outlook将数据存档到
格式。例如,在汉密尔顿,我们看到这些文件与我们写的交易有关。如果我们想自动
以一种对最终用户来说最自然的方式处理我们需要从这些文件中提取数据。
这个库是在优秀的compoundfiles库之上构建的,没有 这一切都不可能。
开始
使用pip安装:
pip install outlook_msg
用法
打开电子邮件:
fromoutlook_msgimportMessagewithopen('file.msg')asmsg_file:msg=Message(msg_file)# Contents are the plaintext body of the emailcontents=msg.body# Attachments can be read and saved like sofirst_attachment=msg.attachments[0]withfirst_attachment.open()asattachment_fp,open(first_attachment.filename,'wb')asoutput_fp:output_fp.write(attachment_fp.read())
运行测试
我们使用pytest来运行我们的测试,但是您最好使用tox,这样您就可以对所有的 支持python版本,并将确保一个干净的环境。