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()withassert_sent_toandsent().
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.