A simple, production-ready Python SDK for sending emails via SMTP
Project description
📧 mailer-sdk
A simple, production-ready Python SDK for sending emails via SMTP. Zero dependencies. Gmail, Outlook, and Yahoo supported out of the box.
Installation
pip install mailer-sdk
Quick Start
from mailer_sdk import Mailer
with Mailer(email="you@gmail.com", password="your-app-password") as mailer:
mailer.send(
to = "friend@example.com",
subject = "Hello!",
body = "Hey, this was sent using mailer-sdk!"
)
Environment Variables (Recommended)
Instead of hardcoding credentials, use environment variables:
export MAILER_EMAIL=you@gmail.com
export MAILER_PASSWORD=your-app-password
export MAILER_PROVIDER=gmail # optional, default is gmail
from mailer_sdk import Mailer
with Mailer() as mailer: # reads from env automatically
mailer.send(to="friend@example.com", subject="Hi", body="Hello!")
Features
| Method | Description |
|---|---|
send() |
Send plain text or HTML email |
send_html() |
Shortcut for HTML emails |
send_bulk() |
Send individually to multiple recipients |
send_template() |
Send HTML with {{placeholder}} fill-in |
send_with_retry() |
Auto-retry with exponential backoff |
Usage Examples
Plain Text
mailer.send(
to = "friend@example.com",
subject = "Hello!",
body = "Plain text email."
)
HTML Email
mailer.send_html(
to = "friend@example.com",
subject = "Welcome!",
body = "<h1>Hello!</h1><p>This is an <b>HTML</b> email.</p>"
)
With CC, BCC, and Attachment
mailer.send(
to = "friend@example.com",
subject = "Report",
body = "Please find the report attached.",
cc = ["manager@example.com"],
bcc = ["archive@example.com"],
attachments = ["report.pdf"]
)
Bulk Send
result = mailer.send_bulk(
recipients = ["a@example.com", "b@example.com", "c@example.com"],
subject = "Newsletter",
body = "Hello, here is this month's update!"
)
print(f"Sent {result['sent']}/{result['total']}")
Template Email
mailer.send_template(
to = "customer@example.com",
subject = "Order Confirmed",
template = "<h2>Hi {{name}}!</h2><p>Order <b>#{{order_id}}</b> confirmed. Total: ${{total}}</p>",
context = {"name": "Alice", "order_id": "1042", "total": "59.99"}
)
Retry on Failure
mailer.send_with_retry(
to = "friend@example.com",
subject = "Important",
body = "Please read this.",
max_retries = 3, # default
backoff = 1 # 1s → 2s → 4s
)
Supported Providers
| Provider | Value |
|---|---|
| Gmail | "gmail" |
| Outlook | "outlook" |
| Yahoo | "yahoo" |
# Outlook example
mailer = Mailer(email="you@outlook.com", password="pass", provider="outlook")
Gmail App Password Setup
Gmail requires an App Password (not your real password):
1. Go to → myaccount.google.com
2. Security → 2-Step Verification (enable it)
3. Security → App Passwords → Generate
4. Copy the 16-character password
5. Use it as your password above
Error Handling
from mailer_sdk import Mailer, AuthError, SendError, ConnectError, ValidationError
try:
with Mailer(email="you@gmail.com", password="wrong-pass") as mailer:
mailer.send(to="friend@example.com", subject="Hi", body="Hello!")
except AuthError as e:
print(f"Auth failed [{e.code}]: {e.message}") # bad credentials
except ConnectError as e:
print(f"Can't connect [{e.code}]: {e.message}") # server unreachable
except SendError as e:
print(f"Send failed [{e.code}]: {e.message}") # delivery failed
except ValidationError as e:
print(f"Bad input [{e.code}]: {e.message}") # invalid inputs
Logging
Control SDK verbosity using Python's standard logging:
import logging
# See all SDK activity
logging.getLogger("mailer_sdk").setLevel(logging.DEBUG)
# Quiet mode — only errors
logging.getLogger("mailer_sdk").setLevel(logging.ERROR)
License
MIT © Your Name
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 mailer_sdk-1.0.2.tar.gz.
File metadata
- Download URL: mailer_sdk-1.0.2.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1c59e83f24568367256b0a3e78950bc60914a316c9b2b0fd5fa4b5561ded214
|
|
| MD5 |
db14a39730d59f8116d45e473c586229
|
|
| BLAKE2b-256 |
ef4ec4a1474431565b83e4a647a6761300a045d40106fd3c39eae94d6535e6da
|
Provenance
The following attestation bundles were made for mailer_sdk-1.0.2.tar.gz:
Publisher:
publish.yml on rishabhsingh06029/mailer-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mailer_sdk-1.0.2.tar.gz -
Subject digest:
d1c59e83f24568367256b0a3e78950bc60914a316c9b2b0fd5fa4b5561ded214 - Sigstore transparency entry: 969218900
- Sigstore integration time:
-
Permalink:
rishabhsingh06029/mailer-sdk@9978c685f656bb3e85e5b9207ed61fa465771445 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/rishabhsingh06029
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9978c685f656bb3e85e5b9207ed61fa465771445 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mailer_sdk-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mailer_sdk-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cb60ef19d59b016223100a2c0dab2ea22cb669eb09ae707d07d7c30bedb7624
|
|
| MD5 |
6127d97a4ebddfca9a1489298056bac4
|
|
| BLAKE2b-256 |
f83c043e46db1cb1089e7f292a0648bafd795f7891835dfde239845167f3fa77
|
Provenance
The following attestation bundles were made for mailer_sdk-1.0.2-py3-none-any.whl:
Publisher:
publish.yml on rishabhsingh06029/mailer-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mailer_sdk-1.0.2-py3-none-any.whl -
Subject digest:
2cb60ef19d59b016223100a2c0dab2ea22cb669eb09ae707d07d7c30bedb7624 - Sigstore transparency entry: 969218902
- Sigstore integration time:
-
Permalink:
rishabhsingh06029/mailer-sdk@9978c685f656bb3e85e5b9207ed61fa465771445 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/rishabhsingh06029
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9978c685f656bb3e85e5b9207ed61fa465771445 -
Trigger Event:
push
-
Statement type: