Skip to main content

wasm_smtp_core/
lib.rs

1//! # wasm-smtp-core
2//!
3//! Environment-independent SMTP client core for WASM and other constrained
4//! runtimes.
5//!
6//! This crate implements the SMTP state machine, response parsing, command
7//! formatting, dot-stuffing, and error classification. It is intentionally
8//! free of any runtime-specific socket code: applications must provide a
9//! [`Transport`] implementation that wraps the runtime-native socket type.
10//! Adapter crates such as `wasm-smtp-cloudflare` provide ready-made
11//! transports.
12//!
13//! ## Scope
14//!
15//! - **Implicit TLS** (port 465) is the standard connection model. The TLS
16//!   handshake itself is the [`Transport`] implementation's responsibility;
17//!   the core operates on an already-secure byte stream. STARTTLS is
18//!   intentionally out of scope for the initial release.
19//! - **MIME composition is out of scope.** Callers pass a fully-formed,
20//!   CRLF-normalized message body string to [`SmtpClient::send_mail`].
21//! - **Bulk delivery, retry queues, and rate limiting are out of scope.** They
22//!   belong in the calling application.
23//!
24//! ## Example
25//!
26//! ```ignore
27//! use wasm_smtp_core::{SmtpClient, Transport};
28//!
29//! async fn send<T: Transport>(transport: T) -> Result<(), wasm_smtp_core::SmtpError> {
30//!     let mut client = SmtpClient::connect(transport, "client.example.com").await?;
31//!     // login() picks the best mechanism the server advertised:
32//!     // PLAIN if available, falling back to LOGIN. For explicit
33//!     // control, use login_with(AuthMechanism::Plain, …).
34//!     client.login("user@example.com", "secret").await?;
35//!     client.send_mail(
36//!         "user@example.com",
37//!         &["recipient@example.org"],
38//!         "From: user@example.com\r\n\
39//!          To: recipient@example.org\r\n\
40//!          Subject: Hello\r\n\
41//!          \r\n\
42//!          Body text.\r\n",
43//!     ).await?;
44//!     client.quit().await?;
45//!     Ok(())
46//! }
47//! ```
48//!
49//! ## Acceptable use
50//!
51//! See `TERMS_OF_USE.md` at the repository root. This crate must not be used
52//! to deliver unsolicited bulk mail, to impersonate other senders, or to
53//! deliver mail that violates the operating policy of any SMTP server.
54
55pub mod client;
56pub mod error;
57pub mod protocol;
58pub mod session;
59pub mod transport;
60
61pub use client::SmtpClient;
62pub use error::{AuthError, InvalidInputError, IoError, ProtocolError, SmtpError, SmtpOp};
63pub use protocol::{AuthMechanism, EnhancedStatus};
64pub use session::SessionState;
65pub use transport::{StartTlsCapable, Transport};
66
67#[cfg(test)]
68mod tests;