[Email-SIG] OffTopic (email lib) : attachments in a forwarded email
PYTHON at telefonica.net
PYTHON at telefonica.net
Mon Nov 24 14:43:41 EST 2003
Hi all,
Firts of all sorry for this off-topic post (I didn´t know where can I
post it). I have a problem when I try to get the attachments of a
forwarded email; I can only get the attach file that contains the "real
attached files I want", not those files
# here is my code:
import pop3lib
impor email.Parser
a = poplib.POP3("pop3.telefonica.net")
a.user(userpop3)
a.pass_(passpop3)
try:
(numMsgs, totalSize) = a.stat()
if numMsgs == 0:
print "Sorry - there are no messages in the mailbox"
else:
for thisNum in range(1, numMsgs + 1):
(server_msg, body, octets) = a.retr(thisNum)
# "cuerpo" now is a string
cuerpo=StringIO.StringIO(string.join(body,'\n'))
p = email.Parser.Parser()
msg = p.parse(cuerpo)
os.chdir(dir_out)
for part in msg.walk():
name= part.get_param("name")
if name != None:
f = open(dir_out + "\\" + name, "wb")
f.write(part.get_payload(decode=1))
f.close
print "Name of the attachment: ", name
a.quit()
#thanks
More information about the Email-SIG
mailing list