Skip to main content

Introduction to Lettermint Laravel

Lettermint Laravel is the official Laravel package for integrating Lettermint email service into your Laravel applications. Send transactional and marketing emails with powerful features like idempotency, routing, webhooks, and comprehensive tracking.

Quick start

Get started with Lettermint in your Laravel application in just a few steps:
1

Install the package

composer require lettermint/lettermint-laravel
2

Configure your API token

Add your Lettermint API token to your .env file:
LETTERMINT_TOKEN=your-lettermint-token
3

Configure the mailer

Add the Lettermint transport to your config/mail.php and service to config/services.php.
4

Send your first email

use Illuminate\Support\Facades\Mail;

Mail::to('[email protected]')
    ->send(new WelcomeEmail($user));

Key features

Installation

Install the package via Composer and publish the configuration file

Configuration

Configure API tokens, routes, idempotency, and multiple mailers

Idempotency

Prevent duplicate emails with automatic or custom idempotency keys

Webhooks

Handle email events with automatic signature verification

Why Lettermint Laravel?

Seamless Laravel integration

Lettermint Laravel integrates directly with Laravel’s native mail system. Use familiar Laravel mail APIs without changing your existing code:
use Illuminate\Support\Facades\Mail;
use App\Mail\OrderConfirmation;

// Works with all Laravel mail features
Mail::to($user)
    ->cc('[email protected]')
    ->send(new OrderConfirmation($order));

// Use tags and metadata
Mail::send((new OrderShipped($order))
    ->tag('transactional')
    ->metadata('order_id', $order->id)
);

// Multiple mailers with different routes
Mail::mailer('lettermint_marketing')
    ->to($user)
    ->send(new NewsletterEmail());

Intelligent idempotency

Prevent duplicate email sends automatically, especially useful for queued jobs that might be retried:
// config/mail.php
'lettermint' => [
    'transport' => 'lettermint',
    'idempotency' => true, // Enable automatic idempotency
    'idempotency_window' => 86400, // 24 hours
],

Route management

Configure multiple mailers with different Lettermint routes for organizing your email traffic:
// config/mail.php
'mailers' => [
    'lettermint_marketing' => [
        'transport' => 'lettermint',
        'route_id' => env('LETTERMINT_MARKETING_ROUTE_ID'),
    ],
    'lettermint_transactional' => [
        'transport' => 'lettermint',
        'route_id' => env('LETTERMINT_TRANSACTIONAL_ROUTE_ID'),
    ],
],

Powerful webhook system

Handle email delivery events with typed Laravel events and automatic signature verification:
use Lettermint\Laravel\Events\MessageDelivered;
use Lettermint\Laravel\Events\MessageHardBounced;

Event::listen(MessageDelivered::class, function (MessageDelivered $event) {
    Log::info('Email delivered', [
        'message_id' => $event->data->messageId,
        'recipient' => $event->data->recipient,
    ]);
});

Event::listen(MessageHardBounced::class, function (MessageHardBounced $event) {
    // Handle permanent bounce - disable the recipient
    User::where('email', $event->data->recipient)
        ->update(['email_disabled' => true]);
});

Enhanced tracking

Add tags and metadata to your emails for better organization and analytics:
Mail::send((new OrderConfirmation($order))
    ->tag('orders')
    ->metadata('order_id', $order->id)
    ->metadata('customer_id', $order->customer_id)
    ->metadata('order_total', $order->total)
);

Requirements

  • PHP 8.2 or higher
  • Laravel 9 or higher

Next steps

Installation guide

Install the package and publish the configuration file

Configuration guide

Set up API tokens, routes, and configure advanced features

Build docs developers (and LLMs) love