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