Skip to main content

Crate mailrs_outbound_queue

Crate mailrs_outbound_queue 

Source
Expand description

Outbound mail queue primitives: DKIM signing, DSN generation, MTA-STS lookup, retry/backoff, plus a pluggable store trait and a Postgres reference implementation.

mailrs-outbound-queue extracts the queue + delivery layer from mailrs so it can be reused — or driven by a custom store — in any Rust MTA. The “pure” pieces (dkim_sign, dsn, mta_sts, retry) depend only on hashes / DNS / pure arithmetic; the QueueStore + Notifier traits in store decouple delivery state from any particular backend.

§Feature flags

FeatureDefaultIncludes
pgonPgQueueStore + KevyNotifier + the bundled DeliveryWorker that consumes them. Pulls in sqlx and kevy-embedded.

Disable the pg feature if you want only the traits + pure primitives:

mailrs-outbound-queue = { version = "1", default-features = false }

§Two paths

The crate exposes two parallel APIs against the same underlying queue semantics:

  • Trait API (QueueStore, Notifier) — the portable surface. Use this if you want a non-PG backend, or if you want your own delivery loop. An always-available InMemoryQueueStore is included for tests + pilots.
  • PG free functions in the queue module — convenience for the common case where you already have a sqlx::PgPool and just want queue::enqueue(pool, ...). These back the bundled DeliveryWorker and are what mailrs itself uses.

Both APIs are stable for v1.x and back-compatible. The trait API plus a generic worker is the target for v2.

Re-exports§

pub use dkim_sign::DkimDomainKey;
pub use dkim_sign::DkimSignConfig;
pub use queue::QueueStatus;
pub use queue::QueuedMessage;
pub use retry::retry_delay_secs;
pub use retry::retry_delay_secs_jittered;
pub use retry::should_bounce;
pub use store::InMemoryNotifier;
pub use store::InMemoryQueueStore;
pub use store::NoopNotifier;
pub use store::Notifier;
pub use store::QueueStore;
pub use store::StoreError;
pub use pg_store::KevyNotifier;
pub use pg_store::PgQueueStore;
pub use worker::DeliveryWorker;
pub use worker::WorkerConfig;
pub use worker::group_by_domain;

Modules§

dkim_sign
DKIM signing helpers (RFC 6376): config + sign-and-prepend. Outbound DKIM signing + ARC sealing, on the mailrs-* crates.
dsn
Delivery Status Notification (RFC 3464) formatting. RFC 3464 Delivery Status Notification (DSN) builder.
mta_sts
MTA-STS (RFC 8461) policy lookup + caching.
pg_store
Postgres-backed QueueStore implementation (feature-gated). Postgres / Kevy-backed implementations of QueueStore and Notifier.
queue
Queue row type, status enum, and retry-attempt bookkeeping.
retry
Exponential-backoff retry math + “is it permanent?” classifier. Exponential-backoff retry helpers for SMTP outbound delivery.
store
Pluggable QueueStore trait + an in-memory reference impl. Storage abstractions for the outbound queue.
worker
Async delivery worker that drains the queue + dispatches via SMTP (feature-gated). Background delivery worker: polls the outbound queue, signs, and delivers to remote MX hosts.

Enums§

DeliveryEvent
Outbound delivery event for external observers (admin UI, audit log, metrics pipeline, TLSRPT reporter).
TlsAttemptOutcome
Outcome of one STARTTLS attempt, carried by DeliveryEvent::TlsAttempt. The four variants discriminate between TLS success, server-side refusal (still safely usable in plain), and handshake failure (with the structured mailrs_smtp_client::TlsOutcome underneath).

Type Aliases§

DeliveryEventSender
Callback channel for DeliveryEvent notifications. Wrapped in Arc so the worker can clone it across spawned delivery tasks.