simple_smtp_sender
A Simple SMTP Email sender crate with the support of sync or async sending. Can be called from Python. Powered by 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
# or
Rust Crate
Add to your Cargo.toml:
[]
# Default: includes Python bindings (requires Python environment)
= "0.2.4"
# Rust-only version (no Python dependencies)
= { = "0.2.4", = false, = ["rslib"] }
Build from Source (requires Rust toolchain and maturin)
# prepare venv and maturin if needed
Or build a wheel:
Requirements
- Python >= 3.10 (for Python package)
- Rust toolchain (for building from source)
Usage
An example test from Rust crate:
Note: this test can only be run natively if you installed with
default-features = false, features = ["rslib"]
use ;
//new builder method
If you installed the Python feature (default), you can test the above codes using for example:
cargo test --no-default-features --features="rslib" send_email_sync_test
An example from Python API:
=
# Synchronous send (blocking)
# With attachment, CC, and BCC:
# Asynchronous send (non-blocking)
await
API
EmailConfig
Configuration class for SMTP server and credentials.
server: SMTP server URLsender_email: Sender's email addressusername: SMTP usernamepassword: SMTP password
send_email(config, recipient, subject, body, cc=None, bcc=None, attachment=None)
Sends an email synchronously (blocking) using the provided configuration.
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)
async_send_email(config, recipient, subject, body, cc=None, bcc=None, attachment=None)
Sends an email asynchronously (non-blocking, returns an awaitable).
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