azure-simple-email
A lightweight Python library for sending email through Microsoft Azure using the Microsoft Graph API.
It wraps the OAuth2 client-credentials flow (via
MSAL)
and the Graph sendMail endpoint into a simple, reusable class — no boilerplate
required.
Features
- Plain-text and HTML emails
- Multiple To / CC / BCC recipients
- File attachments (from disk or in-memory bytes)
- Reply-To header support
- Token caching — send multiple emails without re-authenticating
- Debug mode to redirect all outgoing mail to a test address
Installation
pip install azure-simple-email
Quick start
from azure_simple_email import AzureSendMail
mailer = AzureSendMail(user_id="noreply@example.com")
mailer.add_recipient("alice@example.com")
mailer.send_email(subject="Hello", text="Hi Alice!")
Configuration
The library reads credentials from three environment variables:
| Variable | Description |
|---|---|
AZURE_EMAIL_CLIENT_ID |
Azure AD application (client) ID |
AZURE_EMAIL_CLIENT_SECRET |
Azure AD client secret |
AZURE_EMAIL_CLIENT_AUTHORITY |
Authority URL, e.g. https://login.microsoftonline.com/<tenant-id> |
You can set them in a .env file and load it with
python-dotenv, or export them
directly in your shell.
Setting up the Azure app registration
- Go to Azure portal → Azure Active Directory → App registrations → New registration.
- Under API permissions, add Microsoft Graph → Application permissions → Mail.Send.
- Click Grant admin consent.
- Under Certificates & secrets, create a client secret and copy its value.
Usage examples
HTML email with attachment
from azure_simple_email import AzureSendMail
mailer = AzureSendMail(user_id="noreply@example.com")
mailer.add_recipient("alice@example.com")
mailer.add_attachment("/path/to/report.pdf")
mailer.send_email(
subject="Monthly report",
text="<h1>Report</h1><p>Please find the report attached.</p>",
content_type="HTML",
)
Multiple recipients with CC and BCC
mailer = AzureSendMail(user_id="noreply@example.com")
mailer.add_recipient("alice@example.com")
mailer.add_cc_recipient("bob@example.com")
mailer.add_bcc_recipient("audit@example.com")
mailer.send_email(subject="Update", text="Quarterly update.")
Sending multiple emails (token reuse)
mailer = AzureSendMail(user_id="noreply@example.com")
for address in ["alice@example.com", "bob@example.com"]:
mailer.add_recipient(address)
mailer.send_email(subject="Newsletter", text="Hello!")
mailer.clear() # resets recipients/attachments, keeps the token
See the full documentation and
the examples/ directory for more.
Building the documentation locally
pip install -r docs/requirements.txt
sphinx-build -b html docs/ docs/_build/html
Then open docs/_build/html/index.html in your browser.
License
MIT — see LICENSE.
Metadata
Release files for azure-simple-email 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| azure_simple_email-0.3.0.tar.gz | 18.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| azure_simple_email-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.9 kB
Release files / azure_simple_email-0.3.0.tar.gz
| Download URL | azure_simple_email-0.3.0.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02c616d620320edf43a8553c7ec09ab406cddbd4546c212cd059f8b447adbf16
|
|
BLAKE2b-256 checksum How to use checksums |
cedbe5f1f8504a256709d152415480346671657deff4b5ec4ba96f3c4a9e1a2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 17, 2026.
Transparency logRelease files / azure_simple_email-0.3.0-py3-none-any.whl
| Download URL | azure_simple_email-0.3.0-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca0b3f22d1eae8daaf1879dd524ca9d8ce1def21977fae7d8c899a1e5654d470
|
|
BLAKE2b-256 checksum How to use checksums |
64109c7aa29c6efc99aa1759f3798eca4ba31039848d81a98bb1ebcfa9d012db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 17, 2026.
Transparency logSecurity for azure-simple-email 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for azure_simple_email-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.