简体   繁体   中英

how to use win32com.mapi get new email from outlook in python?

I wanna get a message when a new email into outlook. I try to use python.

I can find that folders,but can't find the way to get the number of new email.

 import win32com.client outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") accounts = win32com.client.Dispatch("Outlook.Application").Session.Accounts; inbox = outlook.Folders(accounts[0].DeliveryStore.DisplayName) for obj in inbox.Folders: #how to know how many new email in this dir? try: if hasattr(obj, "__str__"): dirName = obj.__str__() #as some new email in this obj. for message in obj.items: # how to know this email is not be read? subject = sender = '' if hasattr(message, "Subject"): subject = message.Subject if hasattr(message, "SenderName"): sender = message.SenderName print(sender, subject) except Exception as e: print(f"i:{obj.__str__()}")

and where can I learn win32com.mapi? I wanna know what func can I use in mapi.

give me some info,please~ so much thanks!

Are you looking for unread messages? Use MAPIFolder.Items.Restrict("[Unread] = true") to retrieve Items collection with the restriction applied.

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