简体   繁体   中英

How can I get an email in a specific outlook inbox by date?

How can I, instead of get last, provide a date for it to search for? And if it does not find it get me the previous date

get_path = 'C:\\Users\...'
inbox = outlook.GetDefaultFolder(6)
archiveFolder = inbox.Folders.Item("A")
archiveFolder1 = archiveFolder.Folders.Item("A")
messages = archiveFolder1.Items
message = messages.GetLast()

Assuming you use pywin32 library something like: Here is a link of all methods and properties you can use https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem

And I'm not sure to understand what you mean by previous date... But you will find below an exemple to find message received yesterday:

import datetime
get_path = 'C:\\Users\...'
inbox = outlook.GetDefaultFolder(6)
archiveFolder = inbox.Folders.Item("A")
archiveFolder1 = archiveFolder.Folders.Item("A")
messages = archiveFolder1.Items
for message in messages:
    if message.ReceivedTime.date==datetime.date.today()-datetime.timedelta(days=1):
         #do what you Want with message

Hope it will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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