The above example shows how to print the subject of all of the email in the Inbox. (2) Read the Email # Access to the email in the inbox messages = inbox.Items # get the first email message = messages.GetFirst() # get the last email #message = messages.GetLast() # to loop thru the email in the inbox while True: try: print(message.subject) # get the subject of the email # if you use messages.GetFirst() earlier message = messages.GetNext() # if you use messages.GetPrevious() earlier #message = messages.GetPrevious() except: # if you use messages.GetFirst() earlier message = messages.GetNext() # if you use messages.GetPrevious() earlier #message = messages.GetPrevious() (Reference C2) import win32com.client outlook=("Outlook.Application").GetNamespace("MAPI") for i in range(50): try: box = outlook.GetDefaultFolder(i) name = box.Name print(i, name) except: pass You may check the index of other folders by using the source code below. 3 Deleted Items 4 Outbox 5 Sent Items 6 Inbox 16 Drafts The index of other common items is as below. inbox = outlook.GetDefaultFolder(6) # for sub folder, add inbox = outlook.GetDefaultFolder(6).folders("Testing")Ħ is the index of the inbox. Some Basic Methods / Properties on MailItem Manipulation Establish a Connection to Outlook # set up connection to outlook outlook = ("Outlook.Application").GetNamespace("MAPI")ģ. # pip install pywin32 #if you not installed yet import win32com.clientĢ. This article covers all the basic stuff you need to know to use pywin32 for accessing your Outlook Mailbox. There is also some good application example of pywin32 on various technical writing websites, but they are not complete. Then, the example cannot be used directly when you are scripting in Python. For now, we can only refer to the reference of the Outlook MailItem in Visual Basic for Application (VBA) to learn about the available functions to manipulate the mailbox and the mails. There is no official documentation for pywin32 available. Using pywin32 to Download Specific Mails from Outlook
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |