title: extract email text body without html content in python poplib
body: <p>I need help. This is the email i want to retrieve. Its just a plain text.</p>
  
  <p><a href="https://i.stack.imgur.com/zcm8j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zcm8j.png" alt="enter image description here"></a> </p>
  
  <p>But when I retrieve it the html content is being retrieved as well. This is the example:<a href="https://i.stack.imgur.com/vf6zH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vf6zH.png" alt="enter image description here"></a></p>
  
  <p>What do i need to do to only retrieve the message inside the yellow box?</p>
  
  <p>My code:</p>
  
  <pre><code>import poplib,os
  from email import parser
  pop_conn = poplib.POP3_SSL('pop.gmail.com')
  pop_conn.user('myemail@gmail.com')
  pop_conn.pass_('mypassword')
  #Get messages from server:
  messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
  # Concat message pieces:
  messages = ['\n'.join(map(bytes.decode, mssg[1])) for mssg in messages]
  #Parse message intom an email object:
  messages = [parser.Parser().parsestr(mssg) for mssg in messages]
  
  for message in messages:
      sub= message['subject']
      fr=(message['from'])
      for part in message.walk():
          if part.get_content_type():
              body = str(part.get_payload())
              #print(body)
              with open('file_name.txt','r+') as file:
                  file.write(sub+'\n')
                  file.write(fr+'\n')
                  file.write(body+ os.linesep)
                  lines=file.readlines()
                  lines = [line.rstrip('\n') for line in open('file_name.txt')]
                  file.close()
  pop_conn.quit()
  </code></pre>
  
  <p>I tried to use <code>part.get_payload(decode=True)</code>but the html content is still showing also the text message prints as one long straight line.</p>