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.4"

# Rust-only version (no Python dependencies)
simple_smtp_sender = { version = "0.2.4", 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:

Note: this test can only be run natively if you installed with default-features = false, features = ["rslib"]

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".to_string()], "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".to_string()], "Test Email", "Hello from Rust!", None, None, None).await;
    assert!(result.is_ok());
}

//new builder method
#[test]
fn send_email_sync_builder_test() {
    let config = EmailConfig::new(
        "smtp.example.com",
        "your@email.com",
        "your_username",
        "your_password",
    );
    let result = config
        .send_to(vec!["recipient@email.com".to_string()])
        .subject("Test Email Builder")
        .body("Hello from Rust Email Builder!")
        .send();
    assert!(result.is_ok());
}

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:

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.3.0.tar.gz (16.6 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.3.0-pp311-pypy311_pp73-win_amd64.whl (1.5 MB view details)

Uploaded PyPyWindows x86-64

simple_smtp_sender-0.3.0-cp313-cp313t-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13tWindows x86-64

simple_smtp_sender-0.3.0-cp310-abi3-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

simple_smtp_sender-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl (2.7 MB view details)

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

simple_smtp_sender-0.3.0-cp310-abi3-musllinux_1_2_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

simple_smtp_sender-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

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

simple_smtp_sender-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

simple_smtp_sender-0.3.0-cp310-abi3-macosx_11_0_arm64.whl (732.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for simple_smtp_sender-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2e7374fb114e5bea05b99809047031b37b125783815f1d5bb992e0ca36d24716
MD5 2a2ed3d4e3b06fb3efa1d652a3314afa
BLAKE2b-256 a32b02f823874dcdcdc18aea02a1078e59aa9bd63bea717f36928d761469308c

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.3.0-pp311-pypy311_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-pp311-pypy311_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 32a6351d3bf356cd4ee8658ec0e519e095585a1dda48b9645efbb29fa407e317
MD5 37966fd73a34ba78cfb7139f4adc041f
BLAKE2b-256 f6b4834c66ccb7260702e2f8de10ed4ac3d86b5e5b021bb9615aa926493154b9

See more details on using hashes here.

File details

Details for the file simple_smtp_sender-0.3.0-cp313-cp313t-win_amd64.whl.

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 f7c1ff884ee103768a9b246c7ca90343d9b8909db5a20b28827aa2d35ff1812a
MD5 a13b49e64884f32a84380c916d9f40f3
BLAKE2b-256 004de983a3b0e56493302dd706e2c7658046623de9ad5766c17a5ecae00b2ef3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2effdf40cfdc963a4ec4f2c5fbf47fc6ccce6232b47f48b920abe1c2f7149a23
MD5 c8607ec1b66b1551dddc7a2fa66c7684
BLAKE2b-256 12d10d681e1768c3adc63b816a31e53b39aab0f65e06a4461003d4f69647f985

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b9565b063e1400010288e852303109da6667895afd57507ca389625b07819cdd
MD5 44d142c2a5f71826ba7a12a770babb1e
BLAKE2b-256 be1223447c7e848e17d8c41b39239f1c815461dff1e3dc767b724db595157f41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 180f64eb69059180a1f31fcdbbec6467a5482d6ce320f2cd2cd8b2d1222c3840
MD5 3b9d78b8ef3b0aa1510d341a7098c3e2
BLAKE2b-256 a3a44b6b12724af820d61725adad5003fff969abe703c1e375d79706e2b21a90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5cddf6989dc3cb76e412b3dcd87d31c3f6181c3c8c8d3e7063d009b262f6c658
MD5 f6281d080a2c2c3360a171b656c21ef4
BLAKE2b-256 d29656fb9ae10ea1ad6e1be1fffc82ed2a2be9b40705c437453a642b45222503

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f58c2654a34afcdeb62f0d7b48dc020aab6d89b449a2828b00b9af329f9f4dcf
MD5 25ca2f34ccec3d94ba2e2f82eedbf1e9
BLAKE2b-256 b498c5a567b37bbc8462d609ebdb0a2eb4bfbbb2b44e6b15013f6889c0a3cf11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8db0a4a299ee912448bcb076be12d564a06640f87d59643d126b04b5b3dbaca9
MD5 79a6b50349dfb749fc205ae0dc812a3a
BLAKE2b-256 5e1e0010587dc7287981c01a94923b5981b9719885b7e2d1ef00a907e6ca7496

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