Python email

Tim Williams listserver at
Mon Oct 11 01:26:52 CEST 2004

"LutherRevisited" <lutherrevisited at> wrote in message
news:20041010135948.07384.00002435 at
> I'm attempting to write an email client, and I've run into a snag.  I've
> several docs on email, but they're not dumbed down enough for me.
> I'm downloading my messages like this:
> M = poplib.POP3('')
>         M.user('username')
>         M.pass_('password')
>         inMail = str(M.retr(i))
> and I get the message just fine, but I want to pull out of all that just
> html part.  How can I do this.

as a pointer using your inMail string  (untested,  and you should read the
docs for the email module to find the functions that will really suit your

import email

emailobj  = email.message_from_string(inMail)

# or

emailobj  = email.message_from_string( str(M.retr(i)) )

if not emailobj.is_multipart():
      # return/break/pass etc
e_payload = emailobj.get_payload()

#then something like

for x in range(len(e_payload)):
     e_name = e_payload[x].get_filename()
     e_type = e_payload[x].get_content_type()

# I doubt the last two functions will do what you need,  but there will be
functions in the email module that you can use in their place

More information about the Python-list mailing list