首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何用python打开pst文件( outlook邮件文件)?

如何用python打开pst文件( outlook邮件文件)?
EN

Stack Overflow用户
提问于 2020-01-04 15:55:47
回答 3查看 1.4K关注 0票数 1

我有pst文件,我想用python打开它,我该怎么做?

我尝试过this库,但不起作用。

我的代码是:

代码语言:javascript
运行
复制
import mailparser

mail = mailparser.parse_from_bytes(byte_mail)
mail = mailparser.parse_from_file('c/document/1.pst')
print(mail.attachments)  #list of all attachments

但是得到这个错误:mailparser.exceptions.MailParserOSError: To use this function you must install 'msgconvert' tool

代码语言:javascript
运行
复制
----------All error text:-----------------
To use this function you must install 'msgconvert' tool
Traceback (most recent call last):
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mailparser\utils.py", line 229, in msgconvert
    stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mailparser\utils.py", line 229, in msgconvert
    stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/Drive D/my projects/azar/untitled java 13 12  2019/Pst mail.py", line 3, in <module>
    mail=mailparser.parse_from_file_msg('C:/Users/aa/Documents/1.pst')
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mailparser\mailparser.py", line 89, in parse_from_file_msg
    return MailParser.from_file_msg(fp)
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mailparser\mailparser.py", line 203, in from_file_msg
    f, _ = msgconvert(fp)
  File "C:\Users\aa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mailparser\utils.py", line 234, in msgconvert
    raise MailParserOSError(message)
mailparser.exceptions.MailParserOSError: To use this function you must install 'msgconvert' tool

-----------------------------------
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-01-25 16:00:07

我的解决方案:我将.pst文件转换成.msg文件,然后用Python语言读取(使用app: BitRecover PST Converter Wizard 10.6)。

代码语言:javascript
运行
复制
import extract_msg 
msg = extract_msg.Message("C:/Users/aa/Documents/delete/Untitled.msg") 
print(msg.attachments)`
票数 1
EN

Stack Overflow用户

发布于 2020-01-07 14:24:19

只需在linux环境下运行python脚本即可。

您需要使用以下命令安装Linux包:

代码语言:javascript
运行
复制
$ apt-get install libemail-outlook-message-perl

请浏览以下链接上的描述:https://pypi.org/project/mail-parser/

票数 0
EN

Stack Overflow用户

发布于 2020-10-21 20:20:24

这个看起来不错,https://pypi.org/project/libratom/

代码语言:javascript
运行
复制
from libratom.lib.pff import PffArchive
from email import generator
from pathlib import Path

archive = PffArchive("bill_rapp_000_1_1.pst")
eml_out = Path(Path.cwd() / "emls")

if not eml_out.exists():
  eml_out.mkdir()

print("Writing messages to .eml")
for folder in archive.folders():
    if folder.get_number_of_sub_messages() != 0:
        for message in folder.sub_messages:
            name = message.subject.replace(" ", "_")
            name = name.replace("/","-")
            filename = eml_out / f"{message.identifier}_{name}.eml"
            filename.write_text(archive.format_message(message))
print("Done!")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59588970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档