Benjamin Peterson | fa0d703 | 2009-06-01 22:42:33 +0000 | [diff] [blame] | 1 | .. _email-examples: |
| 2 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 3 | :mod:`email`: Examples |
| 4 | ---------------------- |
| 5 | |
| 6 | Here are a few examples of how to use the :mod:`email` package to read, write, |
| 7 | and send simple email messages, as well as more complex MIME messages. |
| 8 | |
| 9 | First, let's see how to create and send a simple text message: |
| 10 | |
| 11 | .. literalinclude:: ../includes/email-simple.py |
| 12 | |
| 13 | |
| 14 | Here's an example of how to send a MIME message containing a bunch of family |
| 15 | pictures that may be residing in a directory: |
| 16 | |
| 17 | .. literalinclude:: ../includes/email-mime.py |
| 18 | |
| 19 | |
| 20 | Here's an example of how to send the entire contents of a directory as an email |
Christian Heimes | 292d351 | 2008-02-03 16:51:08 +0000 | [diff] [blame] | 21 | message: [1]_ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 22 | |
| 23 | .. literalinclude:: ../includes/email-dir.py |
| 24 | |
| 25 | |
Christian Heimes | 292d351 | 2008-02-03 16:51:08 +0000 | [diff] [blame] | 26 | Here's an example of how to unpack a MIME message like the one |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 27 | above, into a directory of files: |
| 28 | |
| 29 | .. literalinclude:: ../includes/email-unpack.py |
| 30 | |
Christian Heimes | 292d351 | 2008-02-03 16:51:08 +0000 | [diff] [blame] | 31 | Here's an example of how to create an HTML message with an alternative plain |
| 32 | text version: [2]_ |
| 33 | |
| 34 | .. literalinclude:: ../includes/email-alternative.py |
| 35 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 36 | |
| 37 | .. rubric:: Footnotes |
| 38 | |
| 39 | .. [1] Thanks to Matthew Dixon Cowles for the original inspiration and examples. |
Christian Heimes | 292d351 | 2008-02-03 16:51:08 +0000 | [diff] [blame] | 40 | .. [2] Contributed by Martin Matejek. |