I need to setup a method in Python through which I can search for a particular email and get its body and subject. Below is the code I tried:
import win32com.client
class MailApiHelper(object):
def get_latest_email_body(self):
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
# "6" refers to the index of a folder - in this case,
# the inbox. You can change that number to reference
# any other folder
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print body_content
However, I'm not sure how to login and how to perform a search for a particular email.