Chapter 19 Further Reading: Email Automation and Notifications

Official Documentation

Python smtplib https://docs.python.org/3/library/smtplib.html The authoritative reference for Python's SMTP library. Covers all connection modes, the full method API, and exception classes. The "SMTP Objects" section documents every method available on a server object.

Python email package https://docs.python.org/3/library/email.html The complete reference for constructing MIME messages. The "email.mime" subpackage documentation is particularly useful — it covers every MIME type class available in the standard library. The package policy documentation explains the modern vs. legacy API distinction.

Python email.mime.multipart https://docs.python.org/3/library/email.mime.html Reference for MIMEMultipart and related classes. Shows the correct way to build alternative, mixed, and related multi-part messages.

python-dotenv https://pypi.org/project/python-dotenv/ https://github.com/theskumar/python-dotenv Package documentation and source. The README covers advanced usage including variable interpolation, overriding behavior, and loading from specific file paths.

Jinja2 Documentation https://jinja.palletsprojects.com/ Comprehensive documentation for the Jinja2 templating engine. The "Template Designer Documentation" section covers all syntax available in templates. The "API" section covers how to load and render templates from Python.


Email Protocol Standards

RFC 5321 — SMTP https://datatracker.ietf.org/doc/html/rfc5321 The formal specification of the Simple Mail Transfer Protocol. You do not need to read this to use email automation, but it is invaluable if you encounter unusual SMTP behavior or need to debug protocol-level issues.

RFC 2045–2049 — MIME https://datatracker.ietf.org/doc/html/rfc2045 The MIME specification. RFC 2045 covers the MIME message format; RFC 2046 covers media types; RFC 2047 covers non-ASCII in headers. A useful reference if you encounter encoding issues with international characters.


Gmail and Outlook Configuration

Google App Passwords https://support.google.com/accounts/answer/185833 Google's official documentation for generating App Passwords. Includes step-by-step instructions and troubleshooting guidance. Note: 2-Step Verification must be enabled before App Passwords are available.

Gmail SMTP Settings https://support.google.com/mail/answer/7126229 Official SMTP server settings for Gmail: smtp.gmail.com, port 465 (SSL) or 587 (TLS).

Microsoft App Passwords (Outlook) https://support.microsoft.com/en-us/account-billing/using-app-passwords-with-apps-that-don-t-support-two-step-verification-5896ed9b-4263-e681-128a-a6f2979a7944 Microsoft's documentation for generating App Passwords for Outlook and Microsoft 365 accounts.

Outlook/Microsoft 365 SMTP Settings https://support.microsoft.com/en-us/office/pop-imap-and-smtp-settings-8361e398-8af4-4e97-b147-6c6c4ac95353 SMTP settings for Microsoft email accounts: smtp.office365.com, port 587 (TLS).


Slack API and Webhooks

Slack Incoming Webhooks https://api.slack.com/messaging/webhooks Complete documentation for Incoming Webhooks, including setup instructions, payload format, and rate limiting information.

Slack Block Kit https://api.slack.com/block-kit Documentation for Slack's rich message formatting system. Covers all available block types (section, header, actions, context) and field formats.

Slack Block Kit Builder https://app.slack.com/block-kit-builder Interactive tool for designing and previewing Block Kit messages. Extremely useful for prototyping rich Slack messages before writing the Python code.

slack-sdk (Python) https://slack.dev/python-slack-sdk/ The official Python SDK for the Slack API. More powerful than raw webhook calls — enables OAuth flows, bot event handling, and the full Slack API surface.


Email Security and Deliverability

Have I Been Pwned https://haveibeenpwned.com/ Check whether your email accounts appear in known data breaches. If a credential is compromised, it may already be in use by malicious actors. Useful for understanding why credential hygiene matters.

Google Postmaster Tools https://postmaster.google.com/ Tools for monitoring your email domain's reputation with Gmail. Useful if you are sending high-volume automated emails and want to understand deliverability.

Mail Tester https://www.mail-tester.com/ Send a test email to a unique address provided by the site; it analyzes your email and scores it for spam likelihood, SPF/DKIM configuration, and content issues. Useful when debugging deliverability problems.

SPF, DKIM, and DMARC — An Overview https://support.google.com/a/answer/33786 Google's explanation of the three main email authentication standards. If you are sending automated emails from a custom domain and they are landing in spam, these are the first things to check.


Books and Extended Learning

Automate the Boring Stuff with Python by Al Sweigart Free online at https://automatetheboringstuff.com/ Chapter 18 covers sending email with Python. A complementary perspective on the same topic with additional examples.

Python Cookbook by David Beazley and Brian K. Jones (O'Reilly) Recipes in the "Networking and Web" chapter cover advanced socket-level networking that underpins email communication.

The Pragmatic Programmer by David Thomas and Andrew Hunt Not Python-specific, but Chapter 6's discussion of "don't repeat yourself" and automation principles directly applies to why email automation is valuable.


yagmail https://github.com/kootenpv/yagmail A Gmail-specific Python wrapper that simplifies the smtplib/email API significantly. Useful for quick scripts where Gmail is the only provider you need.

sendgrid-python https://github.com/sendgrid/sendgrid-python Python SDK for the SendGrid email delivery service. Appropriate when you are sending thousands of emails (newsletters, transactional email at scale) — proper email service providers handle deliverability, bounce management, and analytics.

Mailgun Python Examples https://documentation.mailgun.com/docs/mailgun/quickstart-guide/whats-in-quickstart/ Mailgun is another email delivery service with a Python SDK. The REST API approach is simpler than raw SMTP for high-volume use cases.

schedule https://schedule.readthedocs.io/ A simple Python scheduling library for running recurring tasks (like sending weekly reports) without configuring a system cron job. Useful for prototyping or running scheduled tasks inside a long-running Python process.


Next Steps

After mastering the content in this chapter, consider these natural extensions:

Email templating systems: Explore building a proper template registry where templates are stored in a database or file system, versioned, and rendered on demand.

Email tracking: Transactional email services like SendGrid and Mailgun provide delivery tracking, open rates, and click tracking — useful for automated reports where you want to confirm delivery.

OAuth authentication: For enterprise scenarios, OAuth 2.0 is replacing App Passwords. The google-auth library and Microsoft's MSAL library handle OAuth flows for Gmail and Outlook respectively.

Async email sending: For high-volume scenarios, Python's asyncio and aiosmtplib allow sending hundreds of emails concurrently without blocking.

IMAP for reading email: Chapter 19 covers only sending. The imaplib standard library module covers reading email — useful for building systems that respond to incoming messages (e.g., processing emailed order forms).