outlook = win32com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")
your_address = [email protected]
inbox = mapi.Folders[your_address].Folders[ Inbox ].Folders[ Apples ]
subject_to_find = "Data List of apples"
email_found = find_email(subject_to_find, inbox)
def find_email(subject, folder):
# Get all emails in the folder
emails = folder.Items
# Use Restrict method to filter emails with a specific subject
filtered_emails = emails.Restrict("[Subject] = " + subject + " ")
# Sort the filtered emails by ReceivedTime in descending order
filtered_emails.Sort("[ReceivedTime]", True)
# Get the most recent email, if any
email = filtered_emails.GetFirst()
return email
我想从电子邮件对话中获得最新的电子邮件; 以下的代码无法在所述文件夹中接收任何邮件 。 但是没有这些限制, 它可以运行到整个电子邮件对话中。 不知道我做错了什么 。