Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
95ce1fcf
Commit
95ce1fcf
authored
Mar 19, 2010
by
Sean Reifscheider
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding an example of reproducing the rfc822.Message() parsing.
parent
cc1d06b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
Doc/includes/email-headers.py
Doc/includes/email-headers.py
+17
-0
Doc/library/email-examples.rst
Doc/library/email-examples.rst
+6
-0
No files found.
Doc/includes/email-headers.py
0 → 100644
View file @
95ce1fcf
# 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'
]
Doc/library/email-examples.rst
View file @
95ce1fcf
...
...
@@ -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:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment