This is an alpha library to send email using Microsoft Graph API, a Microsoft 365 account is required to use this library
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file azure_simple_email-0.3.0.tar.gz.
File metadata
- Download URL: azure_simple_email-0.3.0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02c616d620320edf43a8553c7ec09ab406cddbd4546c212cd059f8b447adbf16
|
|
| MD5 |
93dc4b3a2c10d1b7e6b93dbdfb1c5ef8
|
|
| BLAKE2b-256 |
cedbe5f1f8504a256709d152415480346671657deff4b5ec4ba96f3c4a9e1a2e
|
Provenance
The following attestation bundles were made for azure_simple_email-0.3.0.tar.gz:
Publisher:
ci-cd.yml on marcotn/azure_simple_email
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
azure_simple_email-0.3.0.tar.gz -
Subject digest:
02c616d620320edf43a8553c7ec09ab406cddbd4546c212cd059f8b447adbf16 - Sigstore transparency entry: 1328682705
- Sigstore integration time:
-
Permalink:
marcotn/azure_simple_email@8750f269392464581a545d45dd95a900a6bc398b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/marcotn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@8750f269392464581a545d45dd95a900a6bc398b -
Trigger Event:
push
-
Statement type:
File details
Details for the file azure_simple_email-0.3.0-py3-none-any.whl.
File metadata
- Download URL: azure_simple_email-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca0b3f22d1eae8daaf1879dd524ca9d8ce1def21977fae7d8c899a1e5654d470
|
|
| MD5 |
f3510fc112e2f6220b131efbe1f73cbb
|
|
| BLAKE2b-256 |
64109c7aa29c6efc99aa1759f3798eca4ba31039848d81a98bb1ebcfa9d012db
|
Provenance
The following attestation bundles were made for azure_simple_email-0.3.0-py3-none-any.whl:
Publisher:
ci-cd.yml on marcotn/azure_simple_email
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
azure_simple_email-0.3.0-py3-none-any.whl -
Subject digest:
ca0b3f22d1eae8daaf1879dd524ca9d8ce1def21977fae7d8c899a1e5654d470 - Sigstore transparency entry: 1328682757
- Sigstore integration time:
-
Permalink:
marcotn/azure_simple_email@8750f269392464581a545d45dd95a900a6bc398b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/marcotn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@8750f269392464581a545d45dd95a900a6bc398b -
Trigger Event:
push
-
Statement type: