Sending e-mails
There will be occasions when you may need to send an e-mail from a Python script. An example of this might be an alert for the successful completion or errors incurred in a long-running geoprocessing operation. On these and other occasions, sending an e-mail can be helpful.
Getting ready
Sending an e-mail through a Python script will require you to have access to a mail server. This can be a public e-mail service, such as Yahoo, Gmail, or others. It can also use outgoing mail servers that is configured with applications, such as Microsoft Outlook. In either case, you'll need to know the host name and port of the e-mail server. The Python smtplib
module is used to create connections to the mail server and to send e-mails.
The Python email
module contains a Message
class that represents e-mail messages. Each message contains both headers and a body. This class can't be used to send e-mails, it just handles its object representation. In this recipe, you'll learn...