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
| Backend | When 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§
- Console
Mailer - Development mailer — prints emails to stdout instead of sending.
- One outbound email. Use the builder methods to assemble.
- InMemory
Mailer - Test mailer — captures every sent email into a shared
Vecfor assertions. - Null
Mailer - Discards all emails. Useful for disabling email sending in environments (e.g. CI) without changing call sites.
Enums§
Traits§
- Mailer
- Pluggable async email backend.
Functions§
- from_
settings - Build a
BoxedMailerfrom a loadedcrate::config::MailSettingssection (#87 wiring, v0.29).
Type Aliases§
- Boxed
Mailer Arc<dyn Mailer>alias.