# Framework packages

> Use Sendtide in Laravel, Symfony Mailer, Django and Next.js: mail transport, sending with templates, webhook events and installation.

URL: https://sendtide.ch/en/docs/framework-packages/

Packages for Laravel, Symfony Mailer, Django and Next.js: mail transport, webhook events and sending with templates. Your existing code sends through Sendtide without a rewrite.
The packages build on the official [SDKs](https://sendtide.ch/en/docs/sdks/). Test keys (sk_test_…) accept email and never deliver it, see [Authentication](https://sendtide.ch/en/docs/authentication/#test-and-live).
| Framework | Package | Requirement |
| --- | --- | --- |
| Laravel | composer require sendtide/sendtide-laravel | Laravel 11 or 12, PHP 8.2 or newer |
| Symfony Mailer | composer require sendtide/mailer-bridge | Symfony 6.4, 7 or 8, PHP 8.1 or newer |
| Django | pip install django-sendtide | Django 4.2 LTS or 5.x, Python 3.10 or newer |
| Next.js | npm install @sendtide/next sendtide | Next.js 14 or 15 (App Router), React 18 or 19, Node.js 18.17 or newer |

For other frameworks use [SMTP](https://sendtide.ch/en/docs/smtp/) or one of the [SDKs](https://sendtide.ch/en/docs/sdks/).
## Laravel

The package brings a mail transport, a notification channel, the Sendtide facade and webhook events. Package discovery registers the service provider and the facade.

```
SENDTIDE_API_KEY=sk_live_xxx
MAIL_MAILER=sendtide
MAIL_FROM_ADDRESS=hello@acme.ch
MAIL_FROM_NAME="Acme"
```

With MAIL_MAILER=sendtide every mailable, Mail::raw() and mail notification goes through the Sendtide API. Tags, metadata, attachments and inline images of a mailable are carried over:

```
public function envelope(): Envelope
{
    return new Envelope(
        subject: 'Your invoice',
        tags: ['invoice'],                           // at most 10
        metadata: ['order_id' => $this->order->id],  // returned in webhooks
    );
}

public function headers(): Headers
{
    return new Headers(text: [
        'X-Sendtide-Idempotency-Key' => 'invoice-' . $this->order->id,
    ]);
}
```

Headers with the prefix X-Sendtide- set fields of the API and are not sent as headers: Stream, Tenant, Category, Send-At, Track, Unsubscribe, Template (with Template-Data as JSON), Locale and Idempotency-Key. The returned SentMessage carries the Sendtide id: ->getMessageId() is msg_…. API errors throw a TransportException with the Sendtide error code in the message.

Notifications: the sendtide channel sends a template without a mailable:

```
public function via(object $notifiable): array { return ['sendtide']; }

public function toSendtide(object $notifiable): SendtideMessage
{
    return SendtideMessage::template('invoice-paid', ['amount' => $this->invoice->total])
        ->locale($notifiable->locale ?? 'de-CH')
        ->tag('invoice');
}
```

The idempotency key is derived from the notification id and the recipients, so a retried queued notification goes out once.

Facade: Sendtide::emails()->send([...]), ->batch([...], defaults: [...]) and every other resource of the SDK (templates(), domains(), webhooks(), suppressions(), stats()).

Webhooks: create a webhook in Sendtide for https://your-app/sendtide/webhook and set SENDTIDE_WEBHOOK_SECRET=whsec_…. The route checks Sendtide-Signature against the raw body (HMAC-SHA256, at most 300 seconds old, no CSRF token needed) and answers 400 on a mismatch. For every event it fires WebhookReceived and then the typed event (EmailDelivered, EmailBounced, EmailComplained, EmailReceived and so on, one per [event type](https://sendtide.ch/en/docs/webhooks/)):

```
Event::listen(function (EmailBounced $event) {
    // $event->emailId() (msg_…), $event->recipients(), $event->metadata(), $event->tags()
});
```

A listener that throws makes the route answer 500 and Sendtide delivers the event again later. Slow listeners belong on the queue (ShouldQueue).
## Symfony Mailer

The bridge provides the transport for Symfony Mailer and, with symfony/webhook, a request parser for webhooks. Register the bundle if Flex does not:

```
// config/bundles.php
Sendtide\Symfony\Mailer\SendtideMailerBundle::class => ['all' => true],
```

```
MAILER_DSN=sendtide+api://sk_live_xxx@default
```
| DSN | Sends through |
| --- | --- |
| sendtide+api://KEY@default | the JSON API POST /v1/emails |
| sendtide+smtp://KEY@default | the SMTP gateway smtp.sendtide.ch:587 (STARTTLS) |
| sendtide+smtps://KEY@default | the SMTP gateway on port 465 with TLS |

The API transport carries over sender, recipients, subject, HTML and text, attachments and inline images (embed() becomes cid:), TagHeader as tags and MetadataHeader as metadata. Headers with the prefix X-Sendtide- set the same fields as in Laravel. A message the JSON cannot express (S/MIME, a hand-built MIME body) goes unchanged to POST /v1/emails/mime.

With TemplateEmail subject and content come from a Sendtide template, through the API transport only:

```
$mailer->send(
    (new TemplateEmail())
        ->from('hello@acme.ch')
        ->to('anna@example.com')
        ->template('welcome', ['name' => 'Anna'], 'de-CH')
);
```

Webhooks: with composer require symfony/webhook symfony/remote-event and this routing

```
# config/packages/webhook.yaml
framework:
    webhook:
        routing:
            sendtide:
                service: mailer.webhook.request_parser.sendtide
                secret: '%env(SENDTIDE_WEBHOOK_SECRET)%'
```

you point the webhook to https://your-app/webhook/sendtide. The parser checks the signature (406 on a mismatch) and translates events into MailerDeliveryEvent (delivered, bounce, deferred, dropped) and MailerEngagementEvent (open, click, spam, unsubscribe). You write a consumer with #[AsRemoteEventConsumer('sendtide')].
## Django

The email backend lets send_mail, EmailMessage and EmailMultiAlternatives send through Sendtide unchanged:

```
# settings.py
INSTALLED_APPS = [
    # ...
    "sendtide.django",
]
EMAIL_BACKEND = "sendtide.django.EmailBackend"
DEFAULT_FROM_EMAIL = "Acme <hello@acme.ch>"
SENDTIDE_API_KEY = os.environ["SENDTIDE_API_KEY"]
```

You set fields of the API as attributes of the message:

```
msg = EmailMultiAlternatives(subject="Your invoice", body="Invoice 42 is attached.", to=["anna@example.com"])
msg.attach_file("invoices/42.pdf")
msg.tags = ["invoice"]
msg.metadata = {"order_id": 42}
msg.idempotency_key = "invoice-42"
msg.send()
print(msg.sendtide_id, msg.sendtide_status)  # msg_…, queued
```
| Attribute | API field |
| --- | --- |
| tags, metadata | tags, metadata |
| stream, tenant, category, track, unsubscribe | the same fields |
| template, template_data, locale | template, data, locale |
| send_at | send_at (a naive datetime means UTC) |
| idempotency_key | the Idempotency-Key header |
| sendtide (dict) | merged into the request as is |

Settings live in SENDTIDE = {...} or as SENDTIDE_<NAME> (API key, base URL, timeout, retries, webhook secret). If the API refuses a mail, the backend raises sendtide.SendtideError; with fail_silently=True it stays in msg.sendtide_error.

Webhooks: include the URLs and set SENDTIDE_WEBHOOK_SECRET:

```
# urls.py
urlpatterns = [path("webhooks/sendtide/", include("sendtide.django.urls"))]
```

```
from django.dispatch import receiver
from sendtide.django import signals

@receiver(signals.email_bounced)
def bounced(sender, event, request, **kwargs):
    Customer.objects.filter(email=event["data"]["to"]).update(email_invalid=True)
```

There is one signal per event type (email_delivered, email_bounced, email_received and so on) and signals.webhook_received for all. The view answers 200, 400 for a wrong or expired signature and 500 when a receiver raised (Sendtide then retries for 24 hours).
## Next.js

The helpers for the App Router run on the server (Server Actions, Route Handlers). The key never leaves the server, every helper refuses to run in the browser. Use SENDTIDE_API_KEY without the prefix NEXT_PUBLIC_.

```
"use server";
import { trySendEmail } from "@sendtide/next";
import WelcomeEmail from "@/emails/welcome";

export async function signup(formData: FormData) {
  const { data, error } = await trySendEmail({
    to: String(formData.get("email")),
    subject: "Welcome to Acme",
    react: <WelcomeEmail name={String(formData.get("name"))} />,
    tags: ["signup"],
  });
  if (error) return { ok: false, message: error.message };
  return { ok: true, id: data.id };
}
```

trySendEmail returns { data, error }, sendEmail takes the same arguments, returns { id, status } and throws a SendtideError. With react the package renders the component through @react-email/render (optional, install it separately) to HTML and text. React Email needs the Node.js runtime; on Edge you send html and text yourself. SENDTIDE_FROM is the default sender.

Webhooks: the handler verifies the signature with Web Crypto and runs on Node.js and Edge:

```
// app/api/webhooks/sendtide/route.ts
import { createWebhookHandler } from "@sendtide/next/webhooks";

export const POST = createWebhookHandler({
  on: {
    "email.bounced": async (event) => { await markAddressInvalid(event.data.to as string); },
    "*": (event) => console.log("sendtide", event.type, event.id),
  },
});
```

It answers 200, 400 for a missing or wrong signature and 500 when a handler threw (Sendtide retries). The secret comes from SENDTIDE_WEBHOOK_SECRET.
## Next steps
- [Webhooks](https://sendtide.ch/en/docs/webhooks/): events, signature and retries
- [CLI](https://sendtide.ch/en/docs/cli/): test webhooks locally and fire events
- [SDKs](https://sendtide.ch/en/docs/sdks/): the foundation of these packages
