Mailables render views and go out through any transport.

A mailable is an envelope and content. The content is an ordinary template, so a mail is previewable and testable like a page.

What you get

  • Transports: SMTP, Amazon SES, Postmark, Mailgun, SendGrid and Resend.
  • Log, file and memory transports for development and tests.
  • Mailer::fake() with assert_sent_to and sent().

In the docs

src/app/mail/welcome.rs
use rainier_framework::prelude::*;

pub struct WelcomeEmail {
    pub name: String,
    pub email: String,
}

impl Mailable for WelcomeEmail {
    fn envelope(&self) -> Envelope {
        Envelope::new("Welcome!").to(self.email.clone())
    }

    fn content(&self) -> Result<Content> {
        // resources/views/mail/welcome.view.html
        Content::view("mail.welcome", json!({ "name": self.name }))
    }
}

// Through the configured transport: SMTP, SES, Postmark, Mailgun, SendGrid, Resend…
Mail::instance().send(&WelcomeEmail { name, email }).await?;

Up close

Select an image to see it full size.

A Mailable is a struct with an envelope, a view and headers, rendered by the same template engine as pages.
The mail view render and the send appear on the timeline of the request that queued them.
All features

Type to search 2.0.0 docs.