I am using python to open email on the server (POP3). Each email has an attachment that is a redirected email address.
I need to get the address "To:" from the attachment.
I use python to try to help me learn the language, and I'm not so good yet!
The code that I already have is
import poplib, email, mimetypes
oPop = poplib.POP3( 'xx.xxx.xx.xx' )
oPop.user( 'abc@xxxxx.xxx' )
oPop.pass_( 'xxxxxx' )
(iNumMessages, iTotalSize ) = oPop.stat()
for thisNum in range(1, iNumMessages + 1):
(server_msg, body, octets) = oPop.retr(thisNum)
sMail = "\n".join( body )
oMsg = email.message_from_string( sMail )
# now what ??
I understand that I have an email as an instance of the email class, but I'm not sure how to get to the attachment
I know that using
sData = 'To'
if sData in oMsg:
print sData + "", oMsg[sData]
gets the “To:” header from the main message, but how do I get it from the attachment?
I tried
for part in oMsg.walk():
oAttach = part.get_payload(1)
But I'm not sure what to do with the oAttach object. I tried turning it into a string and then passing it to
oMsgAttach = email.message_from_string( oAttach )
. python . .