Skip to main content

EmailLog Model

The EmailLog model tracks all transactional email sends for audit and debugging.

Table: email_logs
Model: App\Models\EmailLog

Database Schema​

ColumnTypeNullableDescription
idbigint unsignedNoPrimary key
correlation_idvarchar(255)NoRequest correlation ID (indexed)
providervarchar(255)NoEmail provider (mailgun, mailjet, etc.)
drivervarchar(255)NoMail driver
from_emailvarchar(255)NoSender address
to_emailvarchar(255)NoRecipient address
subjectvarchar(255)NoEmail subject
statusenumNoqueued (default), sent, delivered, bounced, failed
provider_message_idvarchar(255)YesProvider tracking ID
error_messagetextYesFailure reason
metadatajsonYesProvider response metadata
sent_attimestampYesWhen sent
created_attimestampYes
updated_attimestampYes

Indexes: email_logs_correlation_id_index (correlation_id) and email_logs_lookup_idx (provider, status, created_at).

Constants​

EmailLog::STATUS_QUEUED
EmailLog::STATUS_SENT
EmailLog::STATUS_DELIVERED
EmailLog::STATUS_BOUNCED
EmailLog::STATUS_FAILED

Scopes​

EmailLog::successful()               // status sent or delivered
EmailLog::failed()
EmailLog::forProvider($provider)
EmailLog::forCorrelation($correlationId)
EmailLog::recent($days = 7) // created_at within the last $days days

Usage Notes​

  • Email logs are not scoped by organization; they are platform-wide.
  • Status updates are written by the transactional email service.
  • Rows older than RETENTION_EMAIL_LOGS_DAYS (default 90) are pruned daily by model:prune (PrunesByRetention).