繁体   English   中英

如何从 Outlook 获取所有日期相关信息(Python,win32)

[英]How do I get all date related info from Outlook (Python, win32)

我正在尝试从 Python 从 Outlook 检索到的消息中获取日期相关信息,但由于某些奇怪的原因我不能。

这很奇怪,因为我可以获得有关发件人、email 正文、主题、cc、bc、附件等的所有信息,但是当涉及到 SentOn、CreationTime 或 LastModificationTime 等属性时,IDLE 只会重新启动(没有任何警告、错误和异常)。

这是示例代码:

import win32com.client

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

inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
messages = inbox.Items
message = messages.GetLast()
rec_time = message.CreationTime
body_content = message.body
subj_line = message.subject
print(rec_time, body_content, subj_line)

Output:

>>> 
================= RESTART: C:/Users/XXXXX/Desktop/email.py =================

=============================== RESTART: Shell ===============================
>>> 

当 CreationTime 被注释掉时,这里会失败:

Hi, 



I really think that it is weird that win32 cannot read date info 



Your sincerely, 



Myself

 Andrew

Python 3.7 版,Outlook 2016

刚刚尝试了您的代码,它没有任何问题。 假设您已经采取了一些一般的故障排除步骤,即重新启动计算机等。我建议您执行以下步骤:

  1. 关闭 outlook 的所有实例
  2. Windows 键 + R在安全模式下运行 Outlook 会出现此对话框在此处输入图像描述

输入outlook /safe ,如上图所示。 尝试运行您的脚本(在安全模式下打开 outlook 确保没有 Outlook 加载项/配置干扰)

如果这不起作用,我建议使用调试器(例如 VSCode)并逐行运行以查看脚本终止的位置。 您共享了示例代码,但如果您有未共享的其他代码 - 只能从我的角度进行假设,但您的脚本中可能有某些原因导致此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM