-2
  I'm trying to copy a specific line from the mail body but I don't know how to do that. 
    I thought regex could solve my problem but didn't know how to implement it again.
    
    mail body:
    
    Line1
    line2
    line3
    line4
    line5
    line6 -  File Name
    line7 - count
    
        I want only want to copy the File Name & paste it into an excel file.
    
    
import pandas as pd
import win32com.client as client

outlook = cliet.Dispaatch("Outlook.Application"),GetNameSpace("MAPI")

prod_path = outlook.Folders("emailId").Folders[1].Items

#print(prod_path.FolderPath)

mailbox = mailbox.Restrict("@SQL=(urn:schemas:httmail:subject like 'subject')")

listofmails = []

for mail in mailbox:
     listofmails.append(mail.body)
     #print(mail.body)
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Rohan -
  • 1
  • 1

1 Answers1

0

The Outlook object model supports three main ways of dealing with the message body:

  1. The Body property returns or sets a string representing the clear-text body of the Outlook item.

  2. The HTMLBody property of the MailItem class returns or sets a string representing the HTML body of the specified item. Setting the HTMLBody property will always update the Body property immediately. For example:

     Sub CreateHTMLMail() 
       'Creates a new e-mail item and modifies its properties. 
       Dim objMail As Outlook.MailItem 
       'Create e-mail item 
       Set objMail = Application.CreateItem(olMailItem) 
       With objMail 
        'Set body format to HTML 
        .BodyFormat = olFormatHTML 
        .HTMLBody = "<HTML><BODY>Enter the message <a href="http://google.com">text</a> here. </BODY></HTML>" 
        .Display 
       End With 
      End Sub
    
  3. The Word object model can be used for dealing with message bodies. See Chapter 17: Working with Item Bodies for more information.

So, you can use the Word object model to find out the line of text required for you.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45