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
Installation
from PyPI
# or
from source (requires Rust toolchain and maturin)
# prepare venv and maturin if needed
Or build a wheel:
Requirements
- Python >= 3.10
- Rust toolchain (for building)
Usage
An example test from Rust crate:
use ;
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