| Crates.io | simple_smtp_sender |
| lib.rs | simple_smtp_sender |
| version | 0.3.1 |
| created_at | 2025-05-22 19:39:52.273661+00 |
| updated_at | 2026-01-15 16:42:21.805396+00 |
| description | A Simple SMTP Email sender crate with the support of sync or async sending. Can be called from Python. Powered by PyO3. |
| homepage | |
| repository | https://github.com/guangyuhe/simple_smtp_sender |
| max_upload_size | |
| id | 1685557 |
| size | 58,452 |
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.
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.
uv pip install simple_smtp_sender
# or
pip install simple_smtp_sender
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" }
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
check tests.rs in tests/ for more examples.
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())
EmailConfigConfiguration class for SMTP server and credentials.
__new__ parameters:
server: SMTP server URLsender_email: Sender's email addressusername: SMTP usernamepassword: SMTP passwordAPIs:
load_from_env(): Load configuration from environment variables:
EMAIL_SERVEREMAIL_SENDER_EMAILEMAIL_USERNAMEEMAIL_PASSWORDload_from_map(config_map: dict): Load configuration from a dictionary.send_email(config, recipient, subject, body, cc=None, bcc=None, attachment=None)
config: EmailConfig instancerecipient: 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)
config: EmailConfig instancerecipient: 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)Cargo.toml.pyproject.toml.src/.MIT