Laravel Maily throws two distinct exception types depending on the failure mode. Understanding which exception to expect at each stage of the send lifecycle helps you write resilient mail-sending code, surface meaningful error messages to operators, and debug issues quickly without guesswork.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.
Exception types
MailyException
Thrown for configuration and validation errors detected before the API is contacted — such as a missing API key or an attempt to send to multiple recipients.Extends PHP’s built-in
Exception.MailyTransportException
Thrown for HTTP and connection failures that occur while communicating with the Maily API — such as non-2xx responses, validation rejections from the server, or network timeouts.Extends Symfony’s
TransportException.MailyException
Class:Yugo\Maily\Exceptions\MailyException — extends Exception
This exception is thrown early in the send process, before any network request is made. It indicates a problem with your application’s configuration or the arguments passed to the mail call.
It is thrown in two situations:
-
Missing API key — the
services.maily.keyconfig value is empty or not set:“Missing Maily API key. Please set services.maily.key configuration.”
-
Multiple recipients — more than one address is passed to
->to():“Maily currently only supports a single recipient.”
MailyException to detect and recover from these configuration-level problems:
MailyTransportException
Class:Yugo\Maily\Exceptions\MailyTransportException — extends Symfony’s TransportException
This exception is thrown when communication with the Maily API fails after the transport has attempted to send the request. It covers three scenarios:
-
Non-2xx API response — the Maily API returns an HTTP error status. The exception message includes the HTTP status code and the error detail from the response body:
“Maily API request failed with status 403: Domain not registered for this account”
-
Server-side validation failure — the API returns a
422(or similar) with adetailsarray. The exception message is augmented with field-level detail (see Validation error format):“Maily API request failed with status 422: Validation failed: to: Invalid to address”
-
Connection failure — the transport cannot reach the Maily API after all configured retries are exhausted:
“Could not connect to the Maily API.”
MailyTransportException to handle API and network failures gracefully:
Validation error format
When the Maily API returns a response body that includes adetails array, the transport appends a formatted, human-readable breakdown of each field-level error to the exception message. This makes it straightforward to identify exactly which field failed validation without inspecting the raw response body.
The relevant code from MailyTransport:
field1: message1, field2: message2.
Retry behavior on connection errors
A
MailyTransportException for connection failures is only thrown after all retries are exhausted. By default, retries are disabled (MAILY_RETRY=0). Configure the number of retry attempts via the MAILY_RETRY environment variable and the delay between attempts (in milliseconds) via MAILY_RETRY_DURATION.