Skip to main content

Module email

Module email 

Source
Expand description

Email backends — email::Mailer trait + console/in-memory/null backends. Email backend layer — pluggable async email sending.

§Quick start

use rustango::email::{Mailer, Email, ConsoleMailer};
use std::sync::Arc;

let mailer: Arc<dyn Mailer> = Arc::new(ConsoleMailer::default());

let email = Email::new()
    .to("user@example.com")
    .from("noreply@my-app.com")
    .subject("Welcome!")
    .body("Thanks for signing up.");
mailer.send(&email).await?;

§Backends

BackendWhen to use
[ConsoleMailer]Development — prints emails to stdout. Default.
[InMemoryMailer]Tests — captures emails into a Vec for assertions.
[SmtpMailer]Production — connects to an SMTP relay. (Future slice — currently a stub.)

§Plug your own

Implement Mailer for any third-party transport (SES, SendGrid, Postmark):

use rustango::email::{Mailer, Email, MailError};
use async_trait::async_trait;

pub struct SesMailer { /* ... */ }

#[async_trait]
impl Mailer for SesMailer {
    async fn send(&self, email: &Email) -> Result<(), MailError> {
        // POST to AWS SES, etc.
        Ok(())
    }
}

Structs§

ConsoleMailer
Development mailer — prints emails to stdout instead of sending.
Email
One outbound email. Use the builder methods to assemble.
InMemoryMailer
Test mailer — captures every sent email into a shared Vec for assertions.
NullMailer
Discards all emails. Useful for disabling email sending in environments (e.g. CI) without changing call sites.

Enums§

MailError

Traits§

Mailer
Pluggable async email backend.

Functions§

from_settings
Build a BoxedMailer from a loaded crate::config::MailSettings section (#87 wiring, v0.29).

Type Aliases§

BoxedMailer
Arc<dyn Mailer> alias.