[Tutor] how to get an email attachment

shawn bright nephish at gmail.com
Mon Aug 21 22:50:31 CEST 2006


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060821/f0d3c33f/attachment.htm 


More information about the Tutor mailing list