我正在尝试从 Python 从 Outlook 检索到的消息中获取与日期相关的信息,但由于某些奇怪的原因我不能。
这很奇怪,因为我可以获得有关发件人、电子邮件正文、主题、抄送、密件抄送、附件等的所有信息,但是当涉及到 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)
输出:
>>>
================= RESTART: C:/Users/XXXXX/Desktop/email.py =================
=============================== RESTART: Shell ===============================
>>>
当 CreationTime 被注释掉时,这里是 outpoot:
Hi,
I really think that it is weird that win32 cannot read date info
Your sincerely,
Myself
Andrew
Python 3.7 版,Outlook 2016