Python Forum
Search Outlook Inbox for set of values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search Outlook Inbox for set of values
#1
So im being tasked with capturing status of key things within multiple projects.. The only bad thing is that not everyone follows the email standard for providing their updates.

I can clearly use the search feature in outlook but that means i would have to search one at a time and rather see if i can make something that will search my entire inbox for a set of values.. and also check if the "TO" or "CC" contains 1 specific email address.

I already know how to connect from python to outlook, im using for processing attachments, but not clear how i can search for values and output a list of emails that contain those values and email address.

Can anyone suggestion methods or sources where i can look at how to accomplish, im working on a way i think may work, since i already have working outlook code, but not ready to test yet or post here.. but will once i get something that runs and can ask for specific help.
Reply
#2
Ok so here is what i have so far and i can get a count of messages from my inbox for the last 10 days..
But need to update the For Loop condition to only return records that contain any of the values in my list

import win32com.client
from datetime import datetime, timedelta
from NewStoreEmailVariables import impStores  # THIS IS A USER LISTING STORED IN THE VARIABLE.PY FILE

outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")
  
inbox = mapi.GetDefaultFolder(6)

messages = inbox.Items

# THIS IS USED TO GRAB THE MESSAGE DATE SO IT CAN PROCESS ONLY THE LATEST EMAILS (EXAMPLE BELOW IS LAST 10 DAYS)
received_dt = datetime.now() - timedelta(days=10)
received_dt = received_dt.strftime('%m/%d/%Y %H:%M %p')

messages = messages.Restrict("[ReceivedTime] >= '" + received_dt + "'")

print(messages.count)

for message in messages:
    if message.Class == 43:
        if (str(message.sender) in impStores):
            print(str(message.sender)+ " = " + str(message.subject) + " = " + str(message.ReceivedTime))
Separate file with the following:

impStores = [    
    '353',
    '336',
    '349',
    '345'
    ]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,263 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Save image from outlook email cubangt 1 707 Jun-07-2023, 06:52 PM
Last Post: cubangt
  Mark outlook emails as read using Python! shane88 2 6,575 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  Trying out the parsing/reading of emails from my outlook cubangt 0 6,186 Jan-12-2022, 08:59 PM
Last Post: cubangt
  Need Outlook send email code using python srikanthpython 3 8,272 Feb-28-2021, 01:53 PM
Last Post: asyswow64
  reading shared outlook emails zarize 0 2,453 Mar-03-2020, 01:47 PM
Last Post: zarize
  Search Excel column values jonzee 1 2,610 Dec-21-2019, 02:38 AM
Last Post: Clunk_Head
  Reading email messages on Outlook johnjohn 9 34,911 Apr-03-2019, 10:41 AM
Last Post: Ken2702
  [Outlook] How to delete items from To-Do List? Winfried 1 3,416 Oct-19-2018, 09:05 PM
Last Post: nilamo
  Unable to fetch Outlook Mail body pramodb35 0 4,161 Jul-25-2018, 07:08 AM
Last Post: pramodb35

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020