Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
TABLE 20.1 Python Networking Modules

Each network module has its own documentation on how to use it within your Python programs, so
you may have to do a bit of digging at the docs.python.org website to find just what you’re looking
for. The next two sections demonstrate a couple examples of how to use the modules to provide
networking features in your Python programs. First you’ll see how to incorporate email features into
your Python scripts, and then you’ll see how to read data from webpages and process it in your
Python scripts.


Working with Email Servers


One popular network feature you may run into with your Python scripts is the ability to send email
messages. This can come in handy if you have automated Python scripts that run on their own, and you
need to know if they fail, or if you’d just like to get the data results from your script sent to you in a
convenient format, without having to log in to the Raspberry Pi to view the data.


The smtplib module provides just what you need to interface your Python scripts with the email
system on your server. The following sections first explore how email works in the Linux
environment and then tackle how to use the smtplib module to send email messages from Python
scripts.


Email in the Linux World

Free download pdf