Search by

trail / mail

dodgycoffee

A mailer addon for trail

Package info

source.tube/brindly/trail-mail

Issues

Type:trail-addon

pkg:composer/trail/mail

Statistics

Installs: 0

Dependents: 1

Suggesters: 0

dev-main / 0.1.x-dev 2026-09-30 21:20 UTC

This package is auto-updated.

Last update: 2026-09-30 21:21:04 UTC


README

A mailer addon for trail framework

install

composer require trail/mail

Needs openssl

config

// app.php
'mail' => [
    'dsn' => App::env('MAIL_DSN'),
    'from' => 'hi@example.com',
    'name' => 'Example',
],
# .env
MAIL_DSN="smtps://user%40example.com:password@smtp.example.com:465"

Provider gives a host and a port. Use the scheme that matches the port:

  • port 465: smtps://user:pass@host:465
  • port 587: smtp://user:pass@host:587
  • @, :, and / in the user or password need url encoding (%40, %3A, %2F)
  • no dsn? dev mode logs every letter. prod logs a warning

sending

use Trail\Mail\Letters\Letter;
use Trail\Mail\Outbox\Outbox;

public function __construct(private Outbox $outbox) {}

$this->outbox->send(new Letter(
    to: 'wat@example.com',
    subject: 'me innit',
    text: View::make('mail/welcome', ['user' => $user]),
    html: View::make('mail/welcome-html', ['user' => $user]),    // optional
    replyTo: 'oops@example.com',                                 // optional
    cc: ['also@example.com'],                                    // optional
    bcc: ['shh@example.com'],                                 // optional
));
  • one to per letter. cc and bcc take lists
  • bcc doesnt show up in messages
  • addresses get checked
  • subjects and names are safe
  • if the server says no it yells Undelivered with what the server said

Sending happens during request, so there might be a delay

queue it

Add trail/queue and you can use a worker instead

'mail' => [
    'dsn' => App::env('MAIL_DSN'),
    'from' => 'hi@example.com',
    'queue' => true,
],
  • send() pushes a job,
  • failed sends get retried by queue, Undelivered ends up in queue::failed
  • letters sit in queue_jobs until sent
  • no worker kills mail. app.queue.runNow in config will send right away. good for local dev

your own outbox

Bind anything that implements Outbox in a site addon

$box->bind(Outbox::class, MyOutbox::class);

For testing you have Pigeonhole, which keeps letters in $letters instead of sending them

$box->bind(Outbox::class, Pigeonhole::class);

cli

trail/trail mail::test stuff@example.com

not done yet

  • attachments