Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/yugo412/laravel-maily/llms.txt

Use this file to discover all available pages before exploring further.

This page documents every public class and interface exposed by the yugo/laravel-maily package, extracted directly from source. Use it as the authoritative reference when integrating the transport, listening to delivery events, or handling errors in your Laravel application.

MailyTransport

DetailValue
NamespaceYugo\Maily
ExtendsSymfony\Component\Mailer\Transport\AbstractTransport
Filesrc/MailyTransport.php
MailyTransport is the core driver. It bridges Laravel’s Mail facade with the Maily.id HTTP API by implementing Symfony Mailer’s AbstractTransport contract.

__toString(): string

Returns the string 'maily', which is the transport identifier registered with Laravel’s mailer system. This name is what you set as MAIL_MAILER=maily in your .env file.
public function __toString(): string
{
    return 'maily';
}

doSend(SentMessage $message): void

Executes email delivery. This method is called internally by Symfony Mailer and should not be invoked directly. The following sequence occurs on each call:
  1. Reads services.maily.key from config; throws MailyException if absent.
  2. Converts the SentMessage to a Symfony\Component\Mime\Email object via MessageConverter.
  3. Throws MailyException if more than one To recipient is present.
  4. Sends an authenticated POST /api/v1/emails/send request using Laravel’s Http client, with the configured retry policy and timeout.
  5. Throws MailyTransportException if the response status is non-2xx, including any validation details from the API.
  6. Dispatches MailySentEvent on success.
  7. Catches any ConnectionException that survives all retries and re-throws it as MailyTransportException.
protected function doSend(SentMessage $message): void

API call performed by doSend

EndpointPOST /api/v1/emails/send Authentication — an X-API-Key header containing your Maily API key is attached to every request. Request body fields
from
string
Sender address. Formatted as "Name <email>" when a display name is present, or plain email otherwise. Sourced from the mail’s From header.
to
string
required
Single recipient address. Formatted identically to from. Only one recipient is accepted per request; passing more than one throws MailyException before the HTTP call is made.
subject
string
Email subject line, taken from the message’s Subject header.
html
string
HTML body of the email. null when the message has no HTML part.
text
string
Plain-text body of the email. null when the message has no text part.

MailyServiceProvider

DetailValue
NamespaceYugo\Maily
ExtendsIlluminate\Support\ServiceProvider
Filesrc/MailyServiceProvider.php
Registers and boots the Maily transport into Laravel’s service container and mailer registry.

boot(): void

Performs two actions when the application boots:
  1. Injects mailer config — merges mail.mailers.maily (['transport' => 'maily']) into the runtime configuration so Laravel recognises maily as a valid mailer without requiring a config/mail.php change.
  2. Registers the transport — calls Mail::extend('maily', ...) to bind a factory closure that returns a fresh MailyTransport instance whenever the maily mailer is resolved.
public function boot(): void
{
    config([
        'mail.mailers.maily' => [
            'transport' => 'maily',
        ],
    ]);

    Mail::extend('maily', function (): MailyTransport {
        return new MailyTransport;
    });
}
MailyServiceProvider is listed under extra.laravel.providers in composer.json, so it is auto-discovered by Laravel’s package discovery mechanism. You do not need to add it manually to config/app.php.

MailySentEvent

DetailValue
NamespaceYugo\Maily\Events
Filesrc/Events/MailySentEvent.php
TraitsDispatchable, InteractsWithSockets, SerializesModels
Dispatched by MailyTransport::doSend() after every successful API response. Listen to this event to log delivery IDs, feed analytics dashboards, or monitor API quota usage.

Constructor properties

All properties are declared public readonly and are populated directly from the Maily API JSON response.
id
string
required
Delivery ID assigned by the Maily API. Use this value to correlate log entries or trace a specific send in the Maily dashboard.
status
string
required
Delivery status string returned by the API at the time of the request — for example, "queued".
message
string
required
Human-readable confirmation message from the API — for example, "Email queued for delivery".
data
array
required
Full decoded JSON response body from the API. Useful when you need fields beyond id, status, and message without a separate API lookup.

broadcastOn(): array

Returns a single-element array containing a PrivateChannel named 'maily-event'. If you have Laravel Echo configured and wish to receive delivery notifications in real time, subscribe to this private channel.
public function broadcastOn(): array
{
    return [
        new PrivateChannel('maily-event'),
    ];
}

Example listener

namespace App\Listeners;

use Illuminate\Support\Facades\Log;
use Yugo\Maily\Events\MailySentEvent;

class LogMailyDelivery
{
    public function handle(MailySentEvent $event): void
    {
        Log::info('Maily delivery accepted', [
            'id'      => $event->id,
            'status'  => $event->status,
            'message' => $event->message,
        ]);
    }
}

MailyException

DetailValue
NamespaceYugo\Maily\Exceptions
ExtendsException
Filesrc/Exceptions/MailyException.php
Thrown before any HTTP request is made when a configuration or input constraint is violated. Catching MailyException in your application indicates a problem you can correct in code or configuration — not a transient network failure. Thrown when:
  • The services.maily.key configuration value is empty or missing — message: "Missing Maily API key. Please set services.maily.key configuration."
  • More than one recipient address is present in the To field — message: "Maily currently only supports a single recipient."

MailyTransportException

DetailValue
NamespaceYugo\Maily\Exceptions
ExtendsSymfony\Component\Mailer\Exception\TransportException
Filesrc/Exceptions/MailyTransportException.php
Thrown when communication with the Maily API fails. Because it extends Symfony’s TransportException, Laravel’s mailer infrastructure treats it as a delivery-layer failure. Thrown when:
  • The Maily API returns a non-2xx HTTP status. The exception message includes the status code, the error field from the response body, and any field-level details validation messages.
  • A ConnectionException is caught after all configured retry attempts have been exhausted — message: "Could not connect to the Maily API."

Build docs developers (and LLMs) love