The 'emails' library is a modern Python package designed for building, templating, transforming, signing, and sending emails. It provides a high-level API to compose HTML and plain-text messages, attach files, embed inline images, render templates, apply HTML transformations, sign with DKIM, and send through SMTP without manually constructing MIME trees. Currently at version 1.1.1, the library is actively maintained with regular releases addressing new features and bug fixes.
pip install emailsVerified import paths — ran on the pinned version, not inferred.
This quickstart example demonstrates how to create and send an HTML email using the `emails` library. It initializes an HTML email message with a subject, HTML body, and sender information. It then attempts to send the email via an SMTP server, retrieving SMTP credentials from environment variables for security. The example includes basic error handling for the `send` operation. For full functionality like HTML transformations or templating, remember to install the respective optional dependencies.
Upgrade your Python environment to 3.10 or later. Consider using a virtual environment to manage Python versions for different projects.
Install with `pip install "emails[html]"` to include HTML transformation features.
If you were using DKIM signing, you should now `import dkim` directly and ensure `dkimpy` is installed (implicitly handled by `emails` core requirements if using DKIM features).
Install with `pip install "emails[jinja]"` to enable Jinja2 templating.
Ensure all intended recipients are included in the `to` parameter when calling `message.send()`. If you want CC/BCC headers to appear, set them in the `Message` constructor as `cc='cc@example.com'` or `bcc='bcc@example.com'`.
Double-check your username and password for typos. If using a service like Gmail, generate and use an app-specific password, or ensure 'less secure app access' is enabled (though this option is often deprecated).
Install the library using `pip install emails`. If the error persists, check your project directory for any files or folders named `emails.py` or `emails` and rename them to avoid conflicts.
Ensure the email content is explicitly set as HTML with the correct character set. When using the `emails` library, ensure the `html` parameter is used and, if manually constructing MIME parts, set `Content-Type` to `text/html` and `charset` to `utf-8`. Example: `msg = email(html='<html>...</html>', charset='utf-8', ...)`
Verify the SMTP server address and port number. Check your network connectivity and any local firewall settings. If connecting to a specific email provider, consult their documentation for the correct SMTP configuration, including required SSL/TLS settings.