Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 82713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:39:36+00:00 2026-05-10T21:39:36+00:00

I have an object. fp = open(self.currentEmailPath, rb) p = email.Parser.Parser() self._currentEmailParsedInstance= p.parse(fp) fp.close()

  • 0

I have an object.

    fp = open(self.currentEmailPath, 'rb')     p = email.Parser.Parser()     self._currentEmailParsedInstance= p.parse(fp)     fp.close() 

self.currentEmailParsedInstance, from this object I want to get the body of an email, text only no HTML….

How do I do it?


something like this?

        newmsg=self._currentEmailParsedInstance.get_payload()         body=newmsg[0].get_content....? 

then strip the html from body. just what is that …. method to return the actual text… maybe I mis-understand you

        msg=self._currentEmailParsedInstance.get_payload()         print type(msg) 

output = type ‘list’


the email

Return-Path:
Received: from xx.xx.net (example) by mxx3.xx.net (xxx)
id 485EF65F08EDX5E12 for xxx@xx.com; Thu, 23 Oct 2008 06:07:51 +0200
Received: from xxxxx2 (ccc) by example.net (ccc) (authenticated as xxxx.xxx@example.com) id 48798D4001146189 for example.example@example-example.com; Thu, 23 Oct 2008 06:07:51 +0200
From: ‘example’
To:
Subject: FW: example Date: Thu, 23 Oct 2008 12:07:45 +0800
Organization: example Message-ID: <001601c934c4$xxxx30$a9ff460a@xxx>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=’—-=_NextPart_000_0017_01C93507.F6F64E30′
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Thread-Index: Ack0wLaumqgZo1oXSBuIpUCEg/wfOAABAFEA

This is a multi-part message in MIME format.

——=_NextPart_000_0017_01C93507.F6F64E30
Content-Type: multipart/alternative;
boundary=’—-=_NextPart_001_0018_01C93507.F6F64E30′

——=_NextPart_001_0018_01C93507.F6F64E30
Content-Type: text/plain;
charset=’us-ascii’
Content-Transfer-Encoding: 7bit

From: example.example[mailto:example@example.com]
Sent: Thursday, October 23, 2008 11:37 AM
To: xxxx@example.com
Subject: S/I for example(B/L
No.:4357-0120-810.044)

Please find attached the example.doc),

Thanks.

B.rgds,

xxx xxx

——=_NextPart_001_0018_01C93507.F6F64E30
Content-Type: text/html;
charset=’us-ascii’
Content-Transfer-Encoding: quoted-printable

xmlns:o=3D’urn:schemas-microsoft-com:office:office’ =
xmlns:w=3D’urn:schemas-microsoft-com:office:word’ =
xmlns:st1=3D’urn:schemas-microsoft-com:office:smarttags’ =
xmlns=3D’http://www.w3.org/TR/REC-html40‘>

HTML STUFF till

——=_NextPart_001_0018_01C93507.F6F64E30–

——=_NextPart_000_0017_01C93507.F6F64E30
Content-Type: application/msword;
name=’xxxx.doc’
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=’xxxx.doc’

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAYAAAAAAAAAAA EAAAYgAAAAEAAAD+////AAAAAF8AAAD///////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////s pcEAI2AJBAAA+FK/AAAAAAAAEAAAAAAABgAAnEIAAA4AYmpiaqEVoRUAAAAAAAAAAAAAAAAAAAAA AAAECBYAMlAAAMN/AADDfwAAQQ4AAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAA AAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAKQAAAAAAEYEAAAAAAAARgQAAEYE AAAAAAAARgQAAAAAAABGBAAAAAAAAEYEAAAAAAAARgQAABQAAAAAAAAAAAAAAFoEAAAAAAAA4hsA AAAAAADiGwAAAAAAAOIbAAA4AAAAGhwAAHwAAACWHAAARAAAAFoEAAAAAAAABzcAAEgBAADmHAAA FgAAAPwcAAAAAAAA/BwAAAAAAAD8HAAAAAAAAPwcAAAAAAAA/BwAAAAAAAD8HAAAAAAAAPwcAAAA AAAAMjYAAAIAAAA0NgAAAAAAADQ2AAAAAAAANDYAAAAAAAA0NgAAAAAAADQ2AAAAAAAANDYAACQA AABPOAAAaAIAALc6AACOAAAAWDYAAGkAAAAAAAAAAAAAAAAAAAAAAAAARgQAAAAAAABHLAAAAAAA AAAAAAAAAAAAAAAAAAAAAAD8HAAAAAAAAPwcAAAAAAAARywAAAAAAABHLAAAAAAAAFg2AAAAAAAA

——=_NextPart_000_0017_01C93507.F6F64E30–


I just want to get :

From: xxxx.xxxx [mailto:xxxx@example.com]
Sent: Thursday, October 23, 2008 11:37 AM
To: xxxx@example.com
Subject: S/I for xxxxx (B/L
No.:4357-0120-810.044)

Pls find attached the xxxx.doc),

Thanks.

B.rgds,

xxx xxx


not sure if the mail is malformed! seems if you get an html page you have to do this:

        parts=self._currentEmailParsedInstance.get_payload()         print parts[0].get_content_type()         ..._multipart/alternative_         textParts=parts[0].get_payload()         print textParts[0].get_content_type()         ..._text/plain_         body=textParts[0].get_payload()         print body         ...get the text without a problem!! 

thank you so much Vinko.

So its kinda like dealing with xml, recursive in nature.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:39:37+00:00Added an answer on May 10, 2026 at 9:39 pm

    This will get you the contents of the message

    self.currentEmailParsedInstance.get_payload() 

    As for the text only part you will have to strip HTML on your own, for example using BeautifulSoup.

    Check this link for more information about the Message class the Parser returns. If you mean getting the text part of messages containing both HTML and plain text version of themselves, you can specify an index to get_payload() to get the part you want.

    I tried with a different MIME email because what you pasted seems malformed, hopefully it got malformed when you edited it.

    >>> parser = email.parser.Parser() >>> message = parser.parse(open('/home/vinko/jlm.txt','r')) >>> message.is_multipart() True >>> parts = message.get_payload() >>> len(parts) 2 >>> parts[0].get_content_type() 'text/plain' >>> parts[1].get_content_type() 'message/rfc822' >>> parts[0].get_payload() 'Message Text' 

    parts will contain all parts of the multipart message, you can check their content types as shown and get only the text/plain ones, for instance.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In SQL Plus scripts you can use a substitution variable… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer It depends on how you issue it. If you just… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer Create a second target (duplicate the main one) for the… May 11, 2026 at 11:44 pm

Related Questions

I'm a mechanical engineering grad student and my adviser has just asked me to
I have had a breakdown on my webhost. Now finally it is up again,
I've been a web developer for some time now, and have recently started learning
Anyone familiar with error below? When I run my webapp to generate a dynamic

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.