Skip to main content

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 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

Add to your Cargo.toml:

[dependencies]
# Default: includes Python bindings (requires Python environment)
simple_smtp_sender = "0.2.3"

# Rust-only version (no Python dependencies)
simple_smtp_sender = { version = "0.2.3", default-features = false, features = ["rslib"] }

Build 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
maturin develop

Or build a wheel:

maturin build
pip install target/wheels/simple_smtp_sender-*.whl

Requirements

  • Python >= 3.10 (for Python package)
  • Rust toolchain (for building from source)

Usage

An example test from Rust crate:

use simple_smtp_sender::{send_email_async, send_email_sync, EmailConfig};

#[test]
fn send_email_sync_test() {
    let config = EmailConfig::new(
        "smtp.example.com",
        "your@email.com",
        "your_username",
        "your_password",
    );
    let result = send_email_sync(config, vec!["recipient@email.com"], "Test Email", "Hello from Rust!", None, None, None);
    assert!(result.is_ok());
}

#[tokio::test]
fn send_email_async_test() {
    let config = EmailConfig::new(
        "smtp.example.com",
        "your@email.com",
        "your_username",
        "your_password",
    );
    let result = send_email_async(config, vec!["recipient@email.com"], "Test Email", "Hello from Rust!", None, None, None).await;
    assert!(result.is_ok());
}

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.

  • server: SMTP server URL
  • sender_email: Sender's email address
  • username: SMTP username
  • password: SMTP password

send_email(config, recipient, subject, body, cc=None, bcc=None, attachment=None)

Sends an email synchronously (blocking) using the provided configuration.

  • config: EmailConfig instance
  • recipient: List of recipient email(s)
  • subject: Email subject
  • body: Email body
  • cc: 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: EmailConfig instance
  • recipient: List of recipient email(s)
  • subject: Email subject
  • body: Email body
  • cc: 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

simple_smtp_sender-0.2.3.tar.gz (28.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

simple_smtp_sender-0.2.3-cp310-abi3-win_amd64.whl (716.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

simple_smtp_sender-0.2.3-cp310-abi3-win32.whl (671.2 kB view details)

Uploaded CPython 3.10+Windows x86

simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_i686.whl (3.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_armv7l.whl (3.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (3.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

simple_smtp_sender-0.2.3-cp310-abi3-macosx_11_0_arm64.whl (848.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

simple_smtp_sender-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl (860.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file simple_smtp_sender-0.2.3.tar.gz.

File metadata

  • Download URL: simple_smtp_sender-0.2.3.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.7

File hashes

Hashes for simple_smtp_sender-0.2.3.tar.gz
Algorithm Hash digest
SHA256 30aafd17128f821871631e8072934bda4e608aa5d6d4909705c0994d4f981419
MD5 62fe780e16e1c361f1765ffb224adeca
BLAKE2b-256 cc10678a58dd5828e4b8d2020ac5df12d18dc37c32fa8a1122d5cebf46b01554

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ef653ad31248cb47820d3d8736369b116e0ef77c519d7259eeb98bf39dba383c
MD5 ddbf614e8f45171fe99c454975d14927
BLAKE2b-256 2874910a6725cffc573bf551bc8381b86b5745b8e23f99bdb09aea9aa361caa9

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 e51590b5c3442e6d569d5e1e337c7e9c13febdf06f91328c8ba05f09439eb804
MD5 39376f40809e897d468343969bd6048c
BLAKE2b-256 994db581c7a44f302eff3505ded52bcfdb72f6fbaf7ccbc6d3b70706aefe9a6f

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a4cf58540eeaaeefa535fbea65949b8ff44dbf58ad4cf922a2ec9b8c86c66206
MD5 8ca8b3023989e4203c6e15401b3a6bd0
BLAKE2b-256 697e83f0850e9c63b4e6fcdeef0100b937154fcf0017ead4ee4dc6c8f04283cb

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 6964ab8bd7642aeb48fe7ae6219784d4081de8421f52a60e4bcc0079e32a83db
MD5 6222f1a836cbbec83fc3845d43a6ce51
BLAKE2b-256 b0953e16dfe74a7649fbba1c2e1df2ffc2c4c67a3876250fbb15786d9b14a790

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 a4b009b4fb9e4c6aff69f2265398b86f5be574a92b404b38b1348708d3dd8b58
MD5 6716c86784dc8f1f0b436bb33620ff2b
BLAKE2b-256 cbb3b6dd9d219197c6d1ef31ea1bad9a546fe6800f176e7090b922055e0d5b88

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4b75cc95f66fe8842124c35e306d83ca9538ca8fb04d3d07e923cc15cf64b32d
MD5 0cd5f6392d7920ad6808c4aac3585411
BLAKE2b-256 42610b8943961b10c1df6082e0f8cdf06f0a4b00975e19f8a420d4f68e1c0959

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6170dcaf1eec01b18813379b2dff18b072db26807bfca3bcbd797668beb5cf8
MD5 6e01f1266a88f485846b93923e77c5a2
BLAKE2b-256 4d34f260c4a06d4cdff6f829b2131db4e0c48355b2c772404298c7f20894a876

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ca62c775acda00264fa611bbb584fd7a66d9e2ffc19f2747f9eb023af22a04eb
MD5 725899e1c397a2c8e69bcf5a87225109
BLAKE2b-256 8ca6ab15b41f8ce61571679ca9c4af7116d7ddf9d13d928438d856fd75b76ed8

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 8b7f1faa8878313a8987692f8e2ea4b2e6f9db363c834438babc2a9d0de1faab
MD5 a1a2196ad90b392d07d6066ebb7caa2d
BLAKE2b-256 ee5265fb662ab4b53d5a58b630a9bfdd10b999fff801d9a57ebcfdcd9cc39e42

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3dc620513730c757402a078dd03a98f6be8478d5c611576b8ba1bfc1c46c6faa
MD5 6e4403d6c5b0a89db5b68703651e0b81
BLAKE2b-256 5e8b7e0a157751fdd12f3b30cde2fc59cf3cf1f3e05582f12a0e29aeb0ffe5a0

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f14085c1e9059b293b3c7002f0eb7ad7dd7a4e22e27b5fe4826dbf9b91cfd0b0
MD5 eb5e170c79207e46fea01d98bcfd52db
BLAKE2b-256 c82b895e9c9b775bffbe3b3772791da42a26211cf05d40cc863e92498b0938d9

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0927588b01f2735bb5aeff0e241d570ae3096667cc255e732b1f51a4e1fae64f
MD5 554bc551a05ae90efd71e73ad40d6da5
BLAKE2b-256 8a0cc6d515a043abad080548c0270f6d058fba56362aa236329c97d6530787a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page