A Simple SMTP Email sender crate with the support of sync or async sending. Can be called from Python. Powered by PyO3.
Project description
simple_smtp_sender
A Simple SMTP Email sender crate with the support of sync or async sending. Can be called from Python. Powered by Rust, lettre and PyO3.
Overview
This project provides rust crate and a Python extension module implemented in Rust for sending emails via SMTP, including support for attachments, CC, and BCC. There are methods for both synchronous and asynchronous sending. It leverages the performance and safety of Rust, exposes a convenient Python API, and is built using PyO3 and lettre. The python module is compatible with Python 3.10 and above.
Features
- Send emails via SMTP synchronously or asynchronously
- Support HTML email contents
- Attach files to emails
- Support for CC and BCC
- Secure authentication
- Easy configuration via Python class
- Flexible feature flags for Rust-only or Python-enabled builds
- No Python dependencies required for Rust-only usage
Installation
Python Package from PyPI
uv pip install simple_smtp_sender
# or
pip install simple_smtp_sender
Rust Crate
Please note that the default feature include the Python PyO3 binding, to use the crate as native
rust pacakge, please declare the dependency with default-feature=false:
[dependencies]
# Rust-only version (no Python dependencies)
simple_smtp_sender = { version = "0.3.1" }
Build Python package from Source (requires Rust toolchain and maturin)
git clone https://github.com/guangyu-he/simple_smtp_sender.git
cd simple_smtp_sender
## prepare venv and maturin if needed
# uv venv
# uv sync
uv run maturin develop
Or build a wheel:
uv run maturin build
pip install target/wheels/simple_smtp_sender-*.whl
Requirements
- Python >= 3.10 (for Python package)
- Rust toolchain (for building from source)
Usage
Rust
check tests.rs in tests/ for more examples.
Python
An example from Python API:
from simple_smtp_sender import EmailConfig, send_email, async_send_email
config = EmailConfig(
server="smtp.example.com",
sender_email="your@email.com",
username="your_username",
password="your_password",
)
# Synchronous send (blocking)
send_email(
config,
recipient=["recipient@email.com"],
subject="Test Email",
body="Hello from Rust!",
)
# With attachment, CC, and BCC:
send_email(
config,
recipient=["recipient@email.com"],
subject="With Attachment",
body="See attached file.",
cc=["cc@email.com"],
bcc=["bcc@email.com"],
attachment="/path/to/file.pdf",
)
# Asynchronous send (non-blocking)
import asyncio
async def main():
await async_send_email(
config,
recipient=["recipient@email.com"],
subject="Async Email",
body="Sent asynchronously!",
)
asyncio.run(main())
API
EmailConfig
Configuration class for SMTP server and credentials.
__new__ parameters:
server: SMTP server URLsender_email: Sender's email addressusername: SMTP usernamepassword: SMTP password
APIs:
load_from_env(): Load configuration from environment variables:EMAIL_SERVEREMAIL_SENDER_EMAILEMAIL_USERNAMEEMAIL_PASSWORD
load_from_map(config_map: dict): Load configuration from a dictionary.
Sends an email synchronously (blocking) using the provided configuration.
send_email(config, recipient, subject, body, cc=None, bcc=None, attachment=None)
config:EmailConfiginstancerecipient: List of recipient email(s)subject: Email subjectbody: Email bodycc: List of CC recipients (optional)bcc: List of BCC recipients (optional)attachment: Path to file to attach (optional)
Sends an email asynchronously (non-blocking, returns an awaitable).
async_send_email(config, recipient, subject, body, cc=None, bcc=None, attachment=None)
config:EmailConfiginstancerecipient: List of recipient email(s)subject: Email subjectbody: Email bodycc: List of CC recipients (optional)bcc: List of BCC recipients (optional)attachment: Path to file to attach (optional)
Development
- Rust dependencies are managed in
Cargo.toml. - Python build configuration is in
pyproject.toml. - Main Rust logic in
src/.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 simple_smtp_sender-0.3.1.tar.gz.
File metadata
- Download URL: simple_smtp_sender-0.3.1.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b11f28e6f27df26ecb8704cb83e12e532cfd96825553366583ae518f6aa0859b
|
|
| MD5 |
82bd0330f61f5c759117c7c8ea85e3cc
|
|
| BLAKE2b-256 |
91571c9493202f33b678e96ce456146933d40ffe2417b91f5830b8679bec8636
|
File details
Details for the file simple_smtp_sender-0.3.1-pp311-pypy311_pp73-win_amd64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-pp311-pypy311_pp73-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: PyPy, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a623a8d9d2d5199934ac4fd4efc8432b59a2bbca297dd83db91014426fa8632c
|
|
| MD5 |
13912265238bd702a5b7355ddb9dc18a
|
|
| BLAKE2b-256 |
d63f76f628b9311bdb9756e85d3afbee3632451aac0a2e5d71babccebf5facf6
|
File details
Details for the file simple_smtp_sender-0.3.1-cp313-cp313t-win_amd64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp313-cp313t-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.13t, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beb511adae716da099550f89ec4e3d94764902bdd8389242ae0cbba1c64fad17
|
|
| MD5 |
2cd0c2f276b81b83edc685e320187ffe
|
|
| BLAKE2b-256 |
aa510770b3a70e56a21c3f81222f710181d4254de35634572ca59eadce8afb21
|
File details
Details for the file simple_smtp_sender-0.3.1-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81a8ed5ba89935327724b4c89c1c1ebb0bc364f0a499dbc34566d9286e858512
|
|
| MD5 |
47c83ef15f9f3df07c41fb95b6a5d77a
|
|
| BLAKE2b-256 |
39b38b97d84c8113856eb33e8a1f03c51970318b2bf1375ec37b558609f83a34
|
File details
Details for the file simple_smtp_sender-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bcb5891aed83f1e95fbc8c5a35f022737bf1e255f6ce5f90b8ede7a54fe7a28
|
|
| MD5 |
ba0e8748a364ea825a6c1d86d29861e2
|
|
| BLAKE2b-256 |
c92f7ad8821437ab9f7f288e311d562f5c8dc45347989524dc7c77bfa83f509d
|
File details
Details for the file simple_smtp_sender-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6324a9d5d9e186d6e0066b35a8b33ebe79c59440d3e996ae947ef0e635c8838
|
|
| MD5 |
a07d76c563964e953dd065bda70abee8
|
|
| BLAKE2b-256 |
de4391e67c9e357110a0f07fc26e10190fd0855d50aea897d252889a12b0d7d1
|
File details
Details for the file simple_smtp_sender-0.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea3779181f8834dfbcbd7022b1beefe37256a66365a3e6c3eeb1a71a1fde44e6
|
|
| MD5 |
af51266bb43021a44fdb84ed9f5ae0b2
|
|
| BLAKE2b-256 |
01a5e8d9a2fcdb9582abb4109f51b851dbd1279d76e6ac10c1d06bb38e702ed9
|
File details
Details for the file simple_smtp_sender-0.3.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2789ee88178f88ac112e53c258efc83f396f78d360ba7d357fa8075cf8b84a2b
|
|
| MD5 |
d0bc39d2726196e7717cb1ce450b9cd3
|
|
| BLAKE2b-256 |
ac3bbeb620ea0d31fa6ffa52d44a328e4f272426515519236f1c7ce5351c5c86
|
File details
Details for the file simple_smtp_sender-0.3.1-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: simple_smtp_sender-0.3.1-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 731.8 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95a6b98d4ccb8f573f90cf06c2610192de5e3658e72e7d1da345a59681aba9e6
|
|
| MD5 |
2ce04ff63d839188d2e75fa049941efa
|
|
| BLAKE2b-256 |
a3b325365f52c304f7e479248020b6df1174812f3e5dbe68d498ec9a544fcaac
|