邮件的ReceivedTime没有在python中显示

问题描述 投票:-1回答:1

我正在尝试阅读我的邮件,并使用MAPI查看Outlook 2016中的收到时间。我能够看到邮件的主题无法看到收到的邮件时间。我知道“Receivedtime”是为了获得邮件的接收时间,但是当程序执行时,会弹出一个弹出窗口,告诉python已停止工作

我知道这不是由于任何机器问题而是我的代码中的一些问题。

这是我的代码。

def arrange(mailbox):
    global spam
    timeperiod() # stores required date in spam[] list
    msgs=mailbox.Items
    msgs.Sort("[ReceivedTime]", True)
    p=msgs.restrict(" [ReceivedTime] >= '"+spam[2]+"'") #and [ReceivedTime] >= '" +spam[1]+"'    
    print(len(p))

    '''
    for m in list1:
        if m.Unread:
            m.Unread=False
            '''
    return p

#Calling it
ctm1=arrange(ctm)

print(len(ctm1)) #Working fine
for message in ctm1:
    print (message.subject) #Also works good
    print (message.receivedTime) # Here is the problem, it's not showing

] 1

我也试过了Senton的财产,但它没有用。所以任何猜测为什么senton或receivedTime属性不工作???

更新的代码:

def printlist(box1) :
print(len(box1))

for message in box1:
    if message.Class==43 :
      #  print('true')
        print (message)
        #.senderEmailAddress) #working
        #print(message.SentOn.strftime("%d-%m-%y")) #not working
        #print(message.body)
        #print(message.UnRead)
        #print (message.receivedTime) #not working
#print('-----------')
python windows outlook pywin32 mapi
1个回答
0
投票

很可能你遇到MailItem以外的项目 - 你也可以在你的收件箱中有ReportItemMeetingItem对象;没有人暴露ReceivedTime财产。

在访问任何其他MailItem特定属性之前,请检查message.Class属性== 43(olMail)。

© www.soinside.com 2019 - 2024. All rights reserved.