out, both of these packages combine the MTA and MDA functions into one software application,
providing a full email server for your system. However, the Raspberry Pi’s Raspbian distribution
doesn’t install either package by default, so you don’t have any email capability for the user accounts
on the Raspberry Pi.
By the Way: sendmail and Postfix on the Raspberry Pi
While not installed by default, both the sendmail and Postfix programs are available in
the Raspbian software repository. You can install either package by using the apt-
get installation tool. If you want to read your mail messages from the command line,
you should also install the mailx program.
Setting up and configuring a full-blown email server on the Internet is not an easy task. However, if
all you need to do is send email messages from your Python scripts to external email addresses,
there’s an easier way than having to set up your own mail server.
We haven’t talked about the MUA package yet. The job of MUA is to provide a method for users to
interface with their existing mailboxes (either on the local system or a remote system) to read and
send email messages.
The smtplib module in Python provides full MUA capabilities, allowing your scripts to connect to
any email server to send email messages—even servers that require encrypted authentication! And
what’s even better, the smtplib package has become so popular that it’s included in the standard
Python library modules, so it’s already available on your Raspberry Pi.
The smtplib Library
The smtplib library includes three classes to create an SMTP connection to a remote email server
and send out messages:
SMTP—The SMTP class connects to the remote email server, using either the standard SMTP
or the extended ESMTP.
SMTP_SSL—The SMTP_SSL class allows you to establish an encrypted session to a remote
email server.
LMTP—The LMTP class offers a more advanced method of connecting to ESMTP servers.
For the scripts in this hour, you’ll be using the SMTP class, but you’ll also see how to encrypt the
password transaction inside the SMTP session. This provides the least amount of overhead for the
session while still keeping transactions secure.
Inside the SMTP class are several methods that you can use to set up and establish the connection with
the email server. Table 20.2 lists these methods.