Skip to main content

Crate mailman

Crate mailman 

Source
Expand description

Rust client SDK for mailman, a microservice that sends emails on your behalf over SMTP.

Mailman ships as two things, mirroring geodude:

  • an HTTP microservice that owns the SMTP credentials and sends mail, and
  • a Rust client crate (this crate’s default client feature) that other services use to ask it to send mail.

§Quickstart

Point at your mailman server once, then send mail from anywhere:

mailman::setup("https://mailman.example.com", "super-secret-token")?;

let email = mailman::SendEmailRequest::new(
    "Hello from mailman",
    "This one's plain text.",
    ["alice@example.com"],
);
mailman::send(&email).await?;

Or read the URL and token from the environment (MAILMAN_URL and MAILMAN_API_TOKEN):

let email = mailman::SendEmailRequest::new(
    "Hello",
    "<h1>Hi!</h1>",
    ["bob@example.com"],
)
.html(true)
.cc(["carol@example.com"]);

// `send` lazily falls back to MAILMAN_URL / MAILMAN_API_TOKEN on first
// call, so the env-only path can skip the init call entirely.
mailman::send(&email).await?;

For multiple servers or finer control over the reqwest::Client, construct a Client directly with Client::new or Client::with_http.

Structs§

Attachment
A single file attachment. content is the file’s bytes encoded as standard (RFC 4648) base64.
Client
HTTP client for a mailman server.
ErrorResponse
The JSON returned by mailman on error: {"error": "..."}.
SendEmailRequest
A request to send an email. This is the JSON body of POST /send.
SendEmailResponse
The JSON returned by POST /send on success.

Enums§

Error
Errors returned by the mailman client.

Functions§

configured_url
The configured base URL, if setup or from_env has run.
from_env
Configure the process-global client by reading MAILMAN_URL and MAILMAN_API_TOKEN.
send
Send an email via the process-global client. Lazily initializes from MAILMAN_URL / MAILMAN_API_TOKEN on first call if not already configured.
setup
Configure the process-global client with an explicit URL and token. The first successful call wins; subsequent calls are no-ops.