|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
trying to use e-mail module
I am trying to supply a text e-mail file to python at the command line, and have the e-mail module print out the sender and recipient of the message. I'm having trouble finding the right functions to use in python's e-mail documentation. Any ideas?
|
|
#2
|
|||
|
|||
|
So far I've got:
import sys from email.Parser import Parser fp = open(sys.argv[1]) parser=Parser() msg = parser.parse(fp) fp.close() ---------- This reads in the email from the file... but how do I get the 'From', 'To', and 'Subject'? |
|
#3
|
||||
|
||||
|
Ok this should work, i havn't tested it but from what i can make out of the doc's (head still spinning) the get_all() function should return the MIME headers from a parsed email..
Quote:
cross your fingers.. Code:
import sys
import email
fp = open(sys.argv[1])
parser=email.Parser()
msg = parser.parse(fp)
subject = msg.get_all('From', None)
subject = msg.get_all('To', None)
subject = msg.get_all('Subject', None)
fp.close()
you might also find parseaddr() interest, there do seem to be allot of different ways to go about doing this ![]() Quote:
Mark. Last edited by netytan : October 23rd, 2003 at 05:02 PM. |
|
#4
|
|||
|
|||
|
Thanks
Ahh thank you. My problem was that I was not using 'Subject'. That doc file is ridiculous
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > trying to use e-mail module |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|