Skip to main content

Crate wasm_smtp_wasi

Crate wasm_smtp_wasi 

Source
Expand description

§wasm-smtp-wasi

WASI sockets adapter for [wasm-smtp], targeting wasm32-wasip2 (WASI 0.2 Component Model) runtimes such as wasmtime and WAMR.

§Quick start

use wasm_smtp_wasi::connect_smtps;

// Implicit TLS on port 465 (recommended).
let mut client = connect_smtps(
    "smtp.example.com",
    465,
    "client.example.com",
).await?;

client.login("user@example.com", "secret").await?;
client.send_mail(
    "user@example.com",
    &["recipient@example.org"],
    "Subject: hello\r\n\r\nBody.\r\n",
).await?;
client.quit().await?;

§TLS

TLS is handled by rustls on top of the WASI byte streams. Certificate validation is enforced and cannot be disabled through the public API. Trust anchors come from the Mozilla root CA set (webpki-roots feature, default) or from the OS at runtime (native-roots feature, not useful on most WASI runtimes).

§STARTTLS

Port 587 STARTTLS is supported via [connect_smtp_starttls]. The TLS upgrade is performed by rustls after the SMTP STARTTLS handshake.

§Build target

This crate is designed for wasm32-wasip2. Building for other targets is only useful for running unit tests; the connection helpers will return a compile-time error on non-WASM targets in release builds.

cargo build --target wasm32-wasip2 -p wasm-smtp-wasi

To run tests on native (without a WASI runtime):

cargo test -p wasm-smtp-wasi

§Feature flags

FlagDefaultDescription
webpki-rootsBundle Mozilla root CA set
native-rootsUse OS trust store (falls back to webpki-roots on WASI)
plaintext-onlyTest / proxy-offload only. No TLS.

§Limitations

  • wasm32-wasip2 target stdlib must be installed.
  • No connection pooling (one transport = one TCP connection).
  • No built-in retry or timeout logic.

Structs§

ConnectOptions
Options controlling TLS behaviour for [connect_smtps][crate::connect_smtps] and [connect_smtps_with][crate::connect_smtps_with].
WasiSmtpError
An error originating in the WASI socket or DNS layer.