3

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.

Tagc
  • 8,736
  • 7
  • 61
  • 114
  • http://stackoverflow.com/questions/5077625/reading-e-mails-from-outlook-with-python-through-mapi this question is similar to yours, for the filtering of emails you need to check on what will you filter the mail. you can use regex or .substr() – Sandeep Hukku Jan 20 '17 at 09:10
  • I guess the above code is for outlook application not if i'm using webmail. Moreover there isn't any authentication in above method – Varun Gogia Jan 20 '17 at 10:55

0 Answers0