Skip to content

Mail and notifications ​

The Mail tabThe Mail tab

The mail lens records every mail message and every notification the application actually sent while a capture was recording. A mail becomes a row once it has been sent; a notification becomes a row once its channel has delivered it.

Rows ​

Mail and notifications share the mail section. The type field tells them apart.

Mail rows (type is mail):

FieldMeaningUnitMissing when
typemailnever
mailableClass of the mailable that was sentnull for mail not sent from a mailable, such as Mail::raw()
subjectSubject linenull when the message has no subject
from, to, cc, bccLists of addresses, each as email or "Name" <email>empty list when there are none
attachmentsNumber of attachmentsnever (0 without attachments)
body_bytesSize of the text body plus the HTML bodybytesnever
durationTime between the mail being handed to the mailer and it being sentmsnull when the start of the send was not seen
timeWhen the send started, counted from the start of the capturemsnever
originThe file and line of your code that sent it, with a short call chainnull when origin.enabled is off

Notification rows (type is notification):

FieldMeaningUnitMissing when
typenotificationnever
notificationClass of the notificationnever
channelChannel it went through, such as mail, database or broadcastnever
notifiableWho received it: a model as Class#id, another object by its class namenever
responseWhat the channel returned, made readablenull when the channel returned nothing
durationTime the channel took to deliver itmsnull when the start of the send was not seen
timeWhen the send started, counted from the start of the capturemsnever
originThe file and line of your code that sent it, with a short call chainnull when origin.enabled is off

A notification sent through the mail channel gives two rows: the notification and the mail it produced.

Totals, warnings and errors ​

The summary gets these totals when at least one row was recorded:

TotalMeaning
mail_sentNumber of mail rows
notifications_sentNumber of notification rows (one per channel a notification went through)

This lens reports no warnings and no errors. A mail that fails to send throws an exception, which the Exceptions lens records when it is reported.

In the dashboard ​

The Mail tab lists mail and notifications in the order they were sent, in one table. Columns appear for the fields that have values, so a capture with only mail shows subject, addresses, attachments and size, and one with notifications also shows notification, channel and notifiable. Duration and the line of code that sent each row come last.

Group the rows by type to see mail and notifications apart, with a count and the total, average and maximum time per group. A row folds out to every field in full, each with a copy button.

Time spent sending mail shows as mail in the overview's time breakdown.

For agents ​

monocle-rows: which mails were sent, to whom, with which subject.

json
{
  "section": "mail",
  "where": [{"field": "type", "op": "=", "value": "mail"}],
  "fields": ["mailable", "subject", "to", "cc", "attachments", "origin"]
}

monocle-rows: which notifications went out, through which channels, to which notifiable.

json
{
  "section": "mail",
  "where": [{"field": "type", "op": "=", "value": "notification"}],
  "fields": ["notification", "channel", "notifiable", "duration"]
}

monocle-list: which recent jobs sent mail (queued mail is sent in a job).

json
{"type": "job", "has": ["mail"], "since": "1h"}

Configuration ​

The lens is on by default and has no options. In the lenses block of config/monocle.php, key it by its class: true runs it, false turns it off (see Lenses).

Other settings that affect this lens:

  • origin decides whether rows carry the line of code that sent the mail or notification.
  • except keeps whole requests and commands out of recording, including what they send.

No mask settings apply to this lens: addresses and subjects are kept as they are.

php
// config/monocle.php
use ExeQue\Monocle\Lenses\MailLens;

'lenses' => [
    // ...
    MailLens::class => true,    // false to turn it off
],

Requirements and limits ​

  • Nothing to install: it uses Laravel's mail and notification events.
  • Only mail and notifications that were sent are recorded. A queued mailable or a queued notification is recorded in the capture of the job that sends it, not in the request that queued it; the dispatch itself shows in the Queue lens.
  • Mail::fake() and Notification::fake() send nothing, so nothing is recorded under them.
  • The message body is not kept, only its size. Headers and attachment contents are not kept either.
  • Messages the mailer sends that are not regular emails are skipped.