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

时间:2019-03-11 13:59:38

标签: python outlook win32com

我正在尝试从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被注释掉时,这里会提示:

Hi, 



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



Your sincerely, 



Myself

 Andrew

Python ver 3.7,Outlook 2016

0 个答案:

没有答案