Kaydet (Commit) 95ce1fcf authored tarafından Sean Reifscheider's avatar Sean Reifscheider

Adding an example of reproducing the rfc822.Message() parsing.

üst cc1d06b3
# Import the email modules we'll need
from email.parser import Parser
# If the e-mail headers are in a file, uncomment this line:
#headers = Parser().parse(messagefile)
# Or for parsing headers in a string, use:
headers = Parser().parsestr('From: <user@example.com>\n'
'To: <someone_else@example.com>\n'
'Subject: Test message\n'
'\n'
'Body would go here\n')
# Now the header items can be accessed as a dictionary:
print 'To: %s' % headers['to']
print 'From: %s' % headers['from']
print 'Subject: %s' % headers['subject']
......@@ -11,6 +11,12 @@ First, let's see how to create and send a simple text message:
.. literalinclude:: ../includes/email-simple.py
And parsing RFC822 headers can easily be done by the parse(filename) or
parsestr(message_as_string) methods of the Parser() class:
.. literalinclude:: ../includes/email-headers.py
Here's an example of how to send a MIME message containing a bunch of family
pictures that may be residing in a directory:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment