Skip to main content

Crate wasm_smtp

Crate wasm_smtp 

Source
Expand description

§wasm-smtp

Environment-independent SMTP client core for WASM and other constrained runtimes.

This crate implements the SMTP state machine, response parsing, command formatting, dot-stuffing, and error classification. It is intentionally free of any runtime-specific socket code: applications must provide a Transport implementation that wraps the runtime-native socket type. Adapter crates such as wasm-smtp-cloudflare provide ready-made transports.

§Scope

  • TLS is required. Implicit TLS (port 465) is the standard connection model. STARTTLS (port 587) is also supported via SmtpClient::connect_starttls and the StartTlsCapable trait; see those pages for usage. In both cases the TLS handshake itself is the Transport implementation’s responsibility — the core operates on an already-secure byte stream.
  • MIME composition is out of scope. Callers pass a fully-formed, CRLF-normalized message body string to SmtpClient::send_mail.
  • Bulk delivery, retry queues, and rate limiting are out of scope. They belong in the calling application.

§Example

use wasm_smtp::{SmtpClient, Transport};

async fn send<T: Transport>(transport: T) -> Result<(), wasm_smtp::SmtpError> {
    let mut client = SmtpClient::connect(transport, "client.example.com").await?;
    // login() picks the best mechanism the server advertised:
    // PLAIN if available, falling back to LOGIN. For explicit
    // control, use login_with(AuthMechanism::Plain, …).
    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?;
    Ok(())
}

§Acceptable use

See TERMS_OF_USE.md at the repository root. This crate must not be used to deliver unsolicited bulk mail, to impersonate other senders, or to deliver mail that violates the operating policy of any SMTP server.

Re-exports§

pub use client::SmtpClient;
pub use client::SmtpClientOptions;
pub use error::AuthError;
pub use error::InvalidInputError;
pub use error::IoError;
pub use error::PolicyError;
pub use error::ProtocolError;
pub use error::SmtpError;
pub use error::SmtpOp;
pub use message_body::MessageBody;
pub use outcome::SendOutcome;
pub use protocol::AuthMechanism;
pub use protocol::DotStufferState;
pub use protocol::EnhancedStatus;
pub use session::SessionState;
pub use transport::StartTlsCapable;
pub use transport::Transport;

Modules§

audit
SMTP session audit events.
client
High-level SMTP client.
error
Error types returned by SMTP operations.
message_body
Streaming message body source for [SmtpClient::send_mail_stream].
outcome
SendOutcome: the result of a successful message submission.
policy
Pre-send policy hook.
protocol
SMTP wire-format helpers.
session
SMTP session state machine.
transport
Transport abstraction for SMTP I/O.