Skip to main content

Crate wasm_smtp_cloudflare

Crate wasm_smtp_cloudflare 

Source
Expand description

§wasm-smtp-cloudflare

Cloudflare Workers socket adapter for wasm-smtp.

This crate is a thin bridge between the Cloudflare Workers runtime’s TCP socket API (worker::Socket) and the wasm-smtp::Transport / wasm-smtp::StartTlsCapable contracts. It does not implement SMTP itself; everything protocol-shaped lives in wasm-smtp.

§Scope

  • Open a TCP connection from a Worker using worker::connect().
  • Configure either Implicit TLS (SecureTransport::On, port 465) or STARTTLS (SecureTransport::StartTls, port 587).
  • Wrap the resulting worker::Socket so it implements both wasm-smtp::Transport and (for STARTTLS) wasm-smtp::StartTlsCapable.
  • Translate Workers-side I/O failures into wasm-smtp::IoError strings.

§Out of scope

  • SMTP state, command formatting, response parsing, dot-stuffing — these belong in wasm-smtp.
  • MIME composition or attachment building — supply a fully-formed RFC 5322 message as the body.

§Quick start (Implicit TLS, port 465)

use wasm_smtp_cloudflare::connect_smtps;

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"],
    "From: user@example.com\r\n\
     To: recipient@example.org\r\n\
     Subject: Hello\r\n\
     \r\n\
     Body text.\r\n",
).await?;
client.quit().await?;

§Quick start (STARTTLS, port 587)

use wasm_smtp_cloudflare::connect_smtp_starttls;

let mut client =
    connect_smtp_starttls("smtp.example.com", 587, "client.example.com").await?;
client.login("user@example.com", "secret").await?;
// ... same as above

§Targets

Production code only runs on wasm32-unknown-unknown inside the Cloudflare Workers runtime. The crate compiles on host targets so that cargo check can validate types and so that the conversion helpers in adapter can be unit-tested against tokio-test mocks — but at runtime, worker::Socket requires the Workers runtime.

Re-exports§

pub use adapter::CloudflareTransport;
pub use integration::connect_smtp_starttls;
pub use integration::connect_smtps;
pub use socket::connect_implicit_tls;
pub use socket::connect_starttls;

Modules§

adapter
CloudflareTransport — the Transport implementation that wraps a Cloudflare Workers worker::Socket.
integration
High-level integration helpers that compose the Cloudflare transport with wasm-smtp.
socket
Cloudflare Workers socket factory.

Structs§

SmtpClient
Re-export of SmtpClient for convenience: connect_smtps returns SmtpClient<CloudflareTransport>. SMTP client driving a single connection.

Enums§

SmtpError
Re-export of SmtpError for convenience. Top-level error type for all SMTP operations.

Traits§

StartTlsCapable
Re-export of StartTlsCapable for callers that want to call upgrade_to_tls directly. Marker for a Transport that can be upgraded to TLS in-place after connection.
Transport
Re-export of the core Transport trait so that callers depending on this crate do not need a direct dependency on wasm-smtp for the most common use. Async byte-oriented transport contract used by crate::SmtpClient.