Sending email in Laravel Rust: mailables, Resend, SES and queues
Mailables as structs, mail views and components, Resend and Amazon SES, failover, queueing versus sending, attachments, previewing in the browser and mail::fake(), shown on a vet clinic's appointment emails.
- queues
- testing
On this page
Email in Laravel Rust will look familiar if you’ve written a Laravel mailable: one type per email, a view for the body, Mail::to($user)->queue(...) to send it. Three things change. A mailable is a struct, the templates are Jinja-style views rather than Blade, and there’s no SMTP transport in the box. You get Resend and Amazon SES instead, plus a way to write your own.
The app in this guide runs a small veterinary clinic. It confirms appointments, reminds owners the day before, and sends the visit summary with the invoice attached afterwards. Those three emails cover nearly everything the mail system does.
Pick a mailer first
A new app’s default mailer is log. It writes each email to the log (sender, recipients, subject and text body at info, HTML at debug) and sends nothing. Keep it for local work; it plays the role Mailpit or MAIL_MAILER=log plays in Laravel PHP.
For real email, Resend is the shortest path. It needs one key and no Cargo feature:
MAIL_MAILER=resend
RESEND_API_KEY=re_your_key
MAIL_FROM_ADDRESS=appointments@pawsandclaws.example
MAIL_FROM_NAME="Paws & Claws Vets"
Amazon SES needs the ses feature in Cargo.toml, and reads the usual AWS variables (or the server’s IAM role if they’re not set):
laravel-rust = { version = "0.1", features = ["ses"] }
MAIL_MAILER=ses
AWS_DEFAULT_REGION=eu-west-1
Tip: failover is built in. Set
MAIL_MAILER=failoverand Laravel tries Resend, then SES, and logs a warning when the first one fails. A reminder email going out late is annoying; one never going out means a missed appointment.
No SMTP? That’s deliberate, and it’s the biggest surprise for Laravel PHP developers. If you need SMTP or another provider, you write a transport: one trait with one send method. The docs show a full Postmark example built on Laravel’s HTTP client.
A mailable is a struct
The confirmation email in Laravel PHP:
class AppointmentConfirmed extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public Appointment $appointment, public string $url) {}
public function envelope(): Envelope
{
return new Envelope(subject: 'Your appointment is booked');
}
public function content(): Content
{
return new Content(view: 'mail.appointment-confirmed');
}
}
And in Laravel Rust, in src/mail.rs:
use laravel::mail::Mailable;
use laravel::prelude::*;
use crate::models::Appointment;
#[derive(Mailable)]
#[mail(subject = "{pet_name}'s appointment is booked")]
pub struct AppointmentConfirmed {
pub appointment: Appointment,
pub pet_name: String,
pub url: String,
}
impl AppointmentConfirmed {
pub fn new(appointment: Appointment) -> laravel::Result<Self> {
let pet_name = appointment.pet.name.clone();
let url = route!(appointments::show, &appointment)?;
Ok(Self { appointment, pet_name, url })
}
}
A few things are doing work here:
- The view is found by name.
AppointmentConfirmedrendersresources/views/mail/appointment-confirmed.html. Override it withview = "..."inside#[mail(...)]. - The subject can use fields.
{pet_name}is filled from the struct, so the owner sees “Biscuit’s appointment is booked”. - Every field reaches the template, so each field’s type must implement
Serialize. Models do already. - The constructor builds computed values once, like the URL, so every place that sends the email gets them right.
The constructor reads appointment.pet, so the caller has to load it: Appointment::query().with(Appointment::pet). Laravel Rust never lazy-loads; forget the with and it panics in development with the exact fix.
The view
Mail views extend Laravel’s responsive layout and import its components, the way <x-mail::message> and <x-mail::button> work in Blade:
<!-- resources/views/mail/appointment-confirmed.html -->
{% extends "laravel::mail.message" %}
{% import "laravel::mail.components" as mail %}
{% block content %}
<h1>See you soon, {{ pet_name }}</h1>
<p>
We've booked {{ pet_name }} in with {{ appointment.vet_name }}.
Please arrive ten minutes early so we can weigh them.
</p>
{% call mail.panel() %}
<strong>{{ appointment.starts_at }}</strong><br>
Paws & Claws, 14 Mill Lane
{% endcall %}
{{ mail.button("Manage appointment", url) }}
{% endblock %}
You don’t write a text version. Laravel renders the same view a second time with simplified components and turns it into plain text, so spam filters and text-only clients get a proper text body. If one bit of markup makes no sense as text, wrap it in {% if not mail_text %}.
To show your logo in the header, set MAIL_LOGO_URL to a PNG about 64 pixels tall. Gmail and Outlook don’t show SVG.
See it in the browser before sending
Laravel PHP lets you return a mailable from a route to preview it. Laravel Rust does too, because derived mailables implement IntoResponse:
// a local-only route
pub async fn preview(appointment: Appointment) -> laravel::Result<AppointmentConfirmed> {
AppointmentConfirmed::new(appointment)
}
Keep this route out of production, the same as you would in PHP.
Sending: queue, send or send_background
Recipients take strings, (email, name) pairs, or your own models once you teach the compiler how. Do that once, in src/models/owner.rs:
use laravel::mail::Address;
impl From<&Owner> for Address {
fn from(owner: &Owner) -> Self {
Address::new(&owner.email).with_name(&owner.name)
}
}
Then in the booking handler:
use laravel::mail;
let appointment = Appointment::query()
.with((Appointment::owner, Appointment::pet))
.find_or_fail(id)
.await?;
mail::to(&appointment.owner)
.queue(AppointmentConfirmed::new(appointment)?)
.await?;
There are three ways to deliver, and the choice matters more than in PHP:
| Method | Waits for provider | Retries | Survives a deploy |
|---|---|---|---|
queue |
no | yes | yes |
send |
yes | no, unless you’re already in a job | n/a |
send_background |
no | no | no |
queue is the right answer in a handler almost every time. Two details are better than Laravel PHP’s defaults:
- The email is rendered when you queue it, not on the worker. A typo in the template fails in the handler, where you’ll see it, instead of on the worker an hour later.
- Queued email is encrypted with your app key, so magic links and reset tokens are safe sitting in Redis. It also waits for the current database transaction to commit, the equivalent of
afterCommit(), and a rollback drops it.
The reminder: delay, or a job?
The reminder goes out the day before. You can delay a queued email:
use laravel::time::ToSpan;
mail::to(&appointment.owner)
.queue(AppointmentReminder::new(appointment)?)
.delay(24.hours())
.on_queue("mail")
.await?;
But the content is fixed when you queue it. If the owner moves the appointment, the reminder still shows the old time. For email that has to reflect the data at the moment it’s sent, queue a small job that loads the appointment and calls send:
use laravel::mail;
use laravel::queue::{Queueable, job};
#[derive(Queueable)]
pub struct SendAppointmentReminder {
pub appointment_id: i64,
}
#[job]
impl SendAppointmentReminder {
async fn handle(self) -> laravel::Result<()> {
let appointment = Appointment::query()
.with((Appointment::owner, Appointment::pet))
.find_or_fail(self.appointment_id)
.await?;
if appointment.cancelled_at.is_some() {
return Ok(());
}
mail::to(&appointment.owner)
.send(AppointmentReminder::new(appointment)?)
.await?;
Ok(())
}
}
send is the right call inside a job: the job already retries if the provider fails.
Attachments: the visit summary and invoice
After the visit, the owner gets the vet’s notes and the invoice as a PDF. Attachments are fields marked #[mail(attach)], kept out of the template:
use laravel::mail::{Attachment, Mailable};
#[derive(Mailable)]
#[mail(subject = "{pet_name}'s visit summary")]
pub struct VisitSummary {
#[mail(to)]
pub owner: Owner,
pub pet_name: String,
pub notes: String,
#[mail(attach)]
pub invoice: Attachment,
}
#[mail(to)] puts the recipient on the mailable itself, so you can skip mail::to:
mail::queue(VisitSummary {
owner,
pet_name,
notes,
invoice: Attachment::from_storage_disk("s3", invoice_path).name("Invoice.pdf"),
})
.await?;
Where the attachment comes from matters for queued email. from_bytes and from_upload put the whole file in the job payload. from_storage and from_storage_disk store only the path, and the worker reads the file when it sends. For anything bigger than a few kilobytes, store it first and attach from storage. Attachments can total 25 MiB.
Testing
mail::fake() is Mail::fake(), and the assertions read the same, with the mailable’s fields available in a typed closure:
use laravel::mail;
use laravel::testing::prelude::*;
#[laravel::test]
async fn booking_emails_the_owner(app: Application) -> laravel::Result<()> {
let mail = mail::fake();
let owner = create!(Owner { name: "Priya", email: "priya@example.com" }).await?;
let pet = create!(Pet { name: "Biscuit", owner: &owner }).await?;
app.post(format!("/pets/{}/appointments", pet.id)).await.assert_redirect();
mail.assert_queued_where::<AppointmentConfirmed>(|queued| {
queued.has_to("priya@example.com") && queued.mailable().pet_name == "Biscuit"
});
Ok(())
}
The fake still renders every email and reads every file attached from a path or storage, so a broken template or a missing PDF fails the test even though nothing is sent.
Quick reference
| Laravel PHP | Laravel Rust |
|---|---|
class X extends Mailable |
#[derive(Mailable)] struct X |
envelope(subject: ...) |
#[mail(subject = "...")] |
content(view: ...) |
resources/views/mail/x.html, or view = "..." |
<x-mail::message> |
{% extends "laravel::mail.message" %} |
<x-mail::button> |
{{ mail.button("Label", url) }} |
Mail::to($user)->queue(...) |
mail::to(&user).queue(...).await? |
->later(now()->addDay(), ...) |
.queue(...).delay(24.hours()) |
attachments() |
#[mail(attach)] field: Attachment |
MAIL_MAILER=smtp |
write a Transport, or use resend / ses |
Mail::fake() |
mail::fake() |
Does Laravel Rust support SMTP?
Not out of the box. It ships resend, ses, log and failover transports. You can add SMTP, Postmark or anything else by implementing the laravel::mail::Transport trait.
What is the default mailer in Laravel Rust?
log. A new app writes every email to the application log and sends nothing until you set MAIL_MAILER, for example to resend with a RESEND_API_KEY.
Should I queue or send email in a Laravel Rust handler?
Queue it with mail::to(...).queue(...). The response doesn't wait on the provider, and the worker retries if the provider fails. send waits for the provider, and send_background doesn't retry or survive a restart.