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.4.tar.gz (14.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.2.4-cp310-abi3-win_amd64.whl (717.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

simple_smtp_sender-0.2.4-cp310-abi3-win32.whl (670.8 kB view details)

Uploaded CPython 3.10+Windows x86

simple_smtp_sender-0.2.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-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.4-cp310-abi3-macosx_11_0_arm64.whl (849.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

simple_smtp_sender-0.2.4-cp310-abi3-macosx_10_12_x86_64.whl (861.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for simple_smtp_sender-0.2.4.tar.gz
Algorithm Hash digest
SHA256 89bd42557fc6adfff34cf477b9cfcf714bd128a4ebd39d8c2450f7b78d397edb
MD5 27b28ef7188f5b389a887f13941d7eee
BLAKE2b-256 7d9772f780db049b03f0da7b9ae299e0ccb0dc550bea07becb0895f57c7d9720

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d319f9c68845b8bc4cd58c424a7821dc13ad888601338fcb669aa5cee0f6c676
MD5 96c968404d9399f83d3a1914cd6cfd28
BLAKE2b-256 433ab95c0e9e28031f26eaad1ea7700ed2f0c968ac774d603528a878a7368c6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 ee3420c3f3b1ec00128bea08b6c8379962e2272d0049b42f023fbb3a121457d6
MD5 8c5f3111c4b6a24856c5b45aa4af934c
BLAKE2b-256 d9f0dc17cfc1731e3c7b37d16d1551d3100cba9d61da98f0144701d1e4659534

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6e7d088e18ab483e5a49597fd15f65766c908417c38be245e3a04a8fdb63e4c2
MD5 2f79ae0336a4b571172401d302e256e5
BLAKE2b-256 5ff2a41ca957b3b7aa10d7b7645e88131671d86339e91b420cc297ebd67ce49d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c467e87d821c4a867df3ccc45349cd68a7c381380af7a2f52c03c8e4493fc9d5
MD5 8b7184b27056ecf59c77bf74e6051a06
BLAKE2b-256 29f5c855588ebd68f3fb49143417443839d71132fcc9cf34a2123e9a2b542c84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 8944f94955c12f2c006d0c22340854c95c0de9b4fa92b20ae291b6d57fabe3a2
MD5 cba44268a81cf0a2712754af62409a15
BLAKE2b-256 520f2aa33908c364b363c927d1424a4184fab3098c877c59b3b4a0bf5bfaee66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b2b493f6bd92e154ddeadae631baa2309de9420b55a300fc0ce7e03bc3ef2de6
MD5 111c00213e1f72d7135c8c81219d17ad
BLAKE2b-256 7d1efac2c04d6eff19924a8fb5742846e68425d54c4b072b5abca89c0220a97f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce178bf3f1aa9695299b8670b128442cfaf570a2ae7ce631cce33d3cdce645e4
MD5 bf0744882c9522e1df955cba5b94a5e0
BLAKE2b-256 779e1c6dc88a2fb6036a4d780895b4bfff88dfabf7599fe454df3af4ed2deeb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fc336bb056cfb0aa1d0549e7e6e795965a970805b56faf8bfc749fcc9f109abd
MD5 3e6c98411da912b5f11d6dfd1268dbe0
BLAKE2b-256 7b5c1463face931cf0fb899797e6204c7d1333bfa3f5cf07110c3cb936c6e12a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 8be9d414d3b9dd2422cbfead9b6db72b72a5f268edad5b0944fce7942e8f32bd
MD5 9c2640dea9cf37e63a0820f958e17b59
BLAKE2b-256 f7eae632c29c0ee6a2524575a314c5e5f920ff4cba06d4fdc0089bd6f22cbefb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 108f5ad3b2193deb5b08e2185146a314d091a31b383c1906be3f0c3f11deeb57
MD5 98f835530930339ca3adb5db3bb15a55
BLAKE2b-256 f8649df653c810359bb6f0564f746c1e58019baea6e6207fc5c46c0e784c5f79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e4fab3993aee0e44d946a4d134eb979473209e35aef5639c8c173bce143dc9c
MD5 aceadecf9f9c714e0c00ea348f80e8c3
BLAKE2b-256 8d01e764968dfd4fa93f1204bb4361b05bd9db51c8a7dbcac91aaf48f56c32c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_smtp_sender-0.2.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b9567625caa346b81725fd8b519b7bf8b7abf6a82c7b8d65257342498f66d9b9
MD5 fc751e498c219e904f91dc90dd350757
BLAKE2b-256 5027f8b32656492366076a6d4126d31ec1573b3f4edb952890238bd73489cb28

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