Search code examples
pythonoutlookmapi

Python MAPI Outlook read emails for a particular year


This func is for Year alone. (Doesn't work)

def daterange(args):
        
        user_inp = datetime.strptime(args,'%Y')

        rmail = object.Restrict("[ReceivedTime] == '" + user_inp.strftime('%Y')+"'")
        return rmail

The Restrict code doesn't work with = , throws error with == and only works with >=

My requirement is all mails from user_inp(2020) or 2019 etc

Please Help !!!


Solution

  • The Restrict code doesn't work with = , throws error with == and only works with >=

    Using the equal operator is not really a good idea. Instead, you need to specify the time and date range. The difference can be a minute, but not equal.

    Read more about the date and time comparisons in Outlook on the Filtering Items Using a Date-time Comparison page.