[Tutor] how to get an email attachment

Alan Gauld alan.gauld at freenet.co.uk
Mon Aug 21 23:57:08 CEST 2006


I'm no expert here, but isn't there a Mime module for
handling mail attachments? Might be worth a look.

Alan G.

----- Original Message ----- 
From: "shawn bright" <nephish at gmail.com>
To: "tutor-python" <tutor at python.org>
Sent: Monday, August 21, 2006 9:50 PM
Subject: [Tutor] how to get an email attachment


> lo there pythoneers !
>
> i have a simple script to pull some emails from a pop server.
> so far, its working. What i need to do is get an attachment. That 
> attachment
> is going to be encoded in base 64.
> so, i am looking and i can't find how to get the attachment. I have 
> some
> info on the base64 module, so i shouldn't have a problem when i get 
> it...
>
> here is what i have so far....
>
> #!/usr/bin/python
>
> import poplib
> import string
> import time
>
> server = poplib.POP3('mail.xit.net')
> server.user('moulder')
> server.pass_('trustno1')
>
> # server.list returns message info from server in
> # form of response, message_list, size where message_list
> # is a list of messages in form of 'message_id size'
> message_list = server.list()
>
> i = 0
> for message in message_list[1]:
>    i += 1
>
>    message_parts = string.split(message,' ')
>    message_id = message_parts[0]
>    print 'message id is %s\n' % message_id
>    total_email_message = server.retr(message_id)[1]
>    for line in total_email_message:
>        print line
>    print 'deleting message....'
>    # not deleting for right now
>    # server.dele(message_id)
>    time.sleep(1)
>    print 'done'
>
> server.quit()
>
> any ideas would be greatly appreciated.
> if you have read this far down, thanks for your time.
>
> sk
> 



More information about the Tutor mailing list