借助Aspose.Email,使用 Python 读取 Outlook MSG 文件
<p><img src="https://image.evget.com/attachment/keditor/image/20250929/105529_7.png"></p><p><strong>Aspose.Email</strong>是一款企业级解决方案,可自动处理和转换电子邮件文件。无需Microsoft Outlook,以编程方式创建、读取和转换电子邮件文件格式。本指南将向您展示如何借助<strong>Aspose.Email</strong>使用Python读取 Outlook MSG文件。我们将通过 .NET 使用 <strong>Aspose.Email for Python</strong>实现该功能。您也可以在其他编程语言中尝试此 SDK。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.Email 正版试用下载,请联系Aspose官方授权代理商慧都科技</strong></span></p>
<div style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>加入Aspose技术交流QQ群(</strong>1041253375<strong>),与更多小伙伴一起探讨提升开发技能。</strong></span></div>
<h2 id="asposeemail-for-python-via-net---outlook-sdk-installation">通过 .NET 安装 Aspose.Email for Python - Outlook SDK 安装</h2>
<p>为了通过 .NET 安装<strong> Aspose.Email for Python</strong>,请在 CMD 中运行以下命令:</p>
<pre class="prettyprint lang-js highlighter-hljs"><code>pip install Aspose.Email-for-Python-via-NET </code></pre>
<p>如果您不想通过 CMD 安装,也可直接<strong>联系慧都科技直接下载SDK 文件</strong>。</p>
<h2 id="code">使用 Python 读取 Outlook MSG 文件 - 代码片段</h2>
<p>现在,我们将实现如何以编程方式读取 MSG 文件。您可以自动处理电子邮件、归档重要消息,并使用解析后的数据进行进一步处理。此 Python SDK 提供了许多功能。我们将使用其中几个最突出的功能。</p>
<p>以下代码示例演示了如何使用 Python 读取 Outlook MSG 文件:</p>
<pre class="prettyprint lang-py highlighter-hljs"><code>import os
import aspose.email as ae
from aspose.email.mapi import MapiMessage
# Define the path for working directory and apply Aspose.Email license.
dataDir = "files"
license = ae.License()
license.set_license("License.lic")
# Load the source MSG file by calling the load method.
msg = MapiMessage.load(dataDir + "MapiMsgWithPoll.msg")
# Get subject
print("Subject: " + msg.subject)
# Get from address
print("From: " + msg.sender_email_address)
# Get body
print("Body: " + msg.body)
# Get recipients information
print("Recipients Count: " + str(len(msg.recipients)))
# Get Attachments information
print ("Attachments Count:" + str(len(msg.attachments)))
# Print attachments information
for index, att in enumerate(msg.attachments):
if att.object_data is not None:
print(att.display_name)</code></pre>
<p>输出:<img src="https://image.evget.com/attachment/keditor/image/20250929/111707_8.png"></p>
<p> </p>
<p>总之,我们介绍了如何以编程方式在 Python 中打开和读取 MSG 文件。这是一个简单易懂的过程,没有任何依赖项。实际上,只需几行代码,您就可以用 Python 读取 Outlook MSG 文件。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.Email 正版试用下载,请联系Aspose官方授权代理商慧都科技</strong></span></p>
<div style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>加入Aspose技术交流QQ群(</strong>1041253375<strong>),与更多小伙伴一起探讨提升开发技能。</strong></span></div>
<h2 id="faqs">常见问题解答</h2>
<p><strong>问:如何在 Python 中打开 Outlook MSG 文件?</strong></p>
<p>答:您可以使用<strong>Aspose.Email for Python </strong>通过 .NET解析 MSG 文件。</p>
<p><strong>问:Outlook 中的 MSG 文件是什么?</strong></p>
<p>答:MSG文件是一种以专有格式保存的 Microsoft Outlook 电子邮件消息,其中存储了电子邮件的主题、正文、发件人/收件人详细信息和附件。</p><br><br>
来源:https://www.cnblogs.com/software-Development/p/19118934
頁:
[1]