You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python/PowerShell读取Outlook邮件时无法访问正文与收件人问题

无法通过Python/PowerShell访问Outlook邮件正文与收件人属性问题

我尝试用Python和PowerShell读取Outlook邮件内容,能正常获取COM对象及邮件主题,但无法访问正文和收件人属性:PowerShell中对应属性返回$null,Python里则抛出com_error(-2147467260, 'Åtgärden avbröts', None, None)错误。

已尝试以下操作:

  • 保持Outlook处于打开状态
  • 在Outlook中手动选择邮件或不选择邮件
  • 将单封邮件单独保存为文件后读取

已查阅多篇相关文章,但问题仍未解决,也找不到合理的原因解释。遗憾的是,我无法使用MS Graph或旧版Exchange PowerShell模块访问收件箱及邮件。

以下是我最新尝试的Python代码:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

for f in outlook.Folders('my@mail.se').Folders:
    if f.Name == "Inkorg":
        try:
            items = f.Items.Restrict("[MessageClass] = 'IPM.Note'")
            items.Sort("[ReceivedTime]", True)
            count = items.Count
            print(f"Found {count} items in 'Inkorg' folder.")
            for i in range(1, count + 1):
                try:
                    item = items.Item(i)
                    # Filter only mail items
                    if item.Class == 43:  # olMailItem = 43
                        print(f"Subject: {item.Subject}")
                        sender = item.SenderName if item.SenderName else "Sender not found"
                        html_body = item.HTMLBody if item.HTMLBody else "HTMLBody not found"
                        print(f"Sender: {sender}")
                        print(f"Body (HTML):\n{html_body[:200]}...")
                except Exception as e:
                    print(f"Error accessing item {i}: {e}")
        except Exception as e:
            print(f"Error accessing folder '{f.Name}': {e}")

内容的提问来源于stack exchange,提问作者Smorkster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 05:37:36