Resend Examples

repository·main·Indexed 41 days ago

https://github.com/resend/resend-examples

A collection of integration examples for Resend across multiple frameworks and languages, including Next.js 16, Astro, Bun, .NET 8.0+, Elixir 1.15+, and Express. Demonstrates patterns for sending emails, handling webhooks, managing audiences, scheduling, and using templates.

Tokens
49.3K
Snippets
172
Records
204
Agent score
50%

What's inside Resend

  1. Overview of Resend features in Next.js

    main

    This project provides implementation examples for various Resend capabilities within a Next.js 16 (App Router) environment using JavaScript and Tailwind CSS 4.

    Available Example Categories

    Sending Emails

    • Basic Send: Simple HTML email sending via API routes.
    • With Attachments: Sending emails with file attachments.
    • With CID Attachments: Embedding inline images using CID.
    • With Templates: Utilizing Resend's hosted templates.
    • With React Email: Building emails using React components.
    • Scheduled Sending: Scheduling emails for future delivery.

    Forms & Server Actions

    • Contact Form: Implementing a Server Action that performs batch sends.

    Receiving Emails

    • Inbound Emails: Receiving and forwarding emails via webhooks.

    Management

    • Audiences: Managing contacts and segments.
    • Domains: Creating domains and viewing DNS records.
    • Automations: Building event-driven workflows and inspecting runs.

    Advanced

    • Better Auth: Implementing authentication with email verification.
    • Prevent Threading: Techniques to stop Gmail from grouping emails into threads.
  2. Available Resend implementation examples

    main

    This repository provides comprehensive examples for sending and receiving emails across various stacks. The following frameworks and languages are supported:

    LanguageFolderFramework
    Next.js (TypeScript)/nextjs-resend-examples/typescriptNext.js 16, React 19
    Next.js (JavaScript)/nextjs-resend-examples/javascriptNext.js 16, React 19
    PHP/php-resend-examplesSlim, Symfony
    Laravel/laravel-resend-examplesLaravel 11
    Python/python-resend-examplesFlask, FastAPI, Django
    Ruby/ruby-resend-examplesSinatra, Rails
    Go/go-resend-examplesChi, Gin
    Java/java-resend-examplesJavalin, Spring Boot
    .NET (C#)/dotnet-resend-examplesASP.NET Minimal APIs, ASP.NET MVC
    Rust/rust-resend-examplesAxum
    Elixir/elixir-resend-examplesPhoenix
    Express/express-resend-examplesExpress 5
    Hono/hono-resend-examplesHono
    Bun/bun-resend-examplesBun.serve()
    Remix/remix-resend-examplesRemix
    Nuxt/nuxt-resend-examplesNuxt 3
    SvelteKit/sveltekit-resend-examplesSvelteKit
    Astro/astro-resend-examplesAstro
    RedwoodJS/redwoodjs-resend-examplesRedwoodJS
    TanStack Start/tanstack-resend-examplesTanStack Start
  3. Explore TanStack Start + Resend example pages

    main

    Once the development server is running at http://localhost:3000, you can access the following functional examples via the browser:

    • / - Home with links to all examples
    • /send-email - Send a basic email
    • /attachments - Send email with attachments
    • /cid-attachments - Send email with inline CID images
    • /scheduling - Schedule an email for later delivery
    • /templates - Send email using a template
    • /prevent-threading - Send emails that avoid Gmail threading
    • /audiences - Manage audiences and contacts
    • /domains - Manage domains
    • /double-optin - Double opt-in subscription flow
    • /inbound - Inbound email information
  4. Available SvelteKit + Resend email examples

    main

    This project provides several implementation patterns for using Resend within a SvelteKit application:

    • Send Email: Basic email sending functionality.
    • Attachments: Sending emails with file attachments.
    • CID Attachments: Embedding images using Content-ID.
    • Scheduling: Scheduling emails for later delivery.
    • Templates: Sending emails using pre-defined Resend templates.
    • Prevent Threading: Using settings to prevent email client threading.
    • Audiences: Managing contacts and audiences.
    • Domains: Listing and managing domains.
    • Double Opt-in: Implementing subscription flows with confirmation.
    • Inbound: Receiving and processing inbound emails.
  5. Capabilities covered in Resend examples

    main

    The examples in this repository cover several core Resend functionalities:

    Sending Emails

    • Basic Send: Simple HTML email delivery.
    • With Attachments: Sending files via URL or base64.
    • With CID Attachments: Using Content-ID for inline/embedded images.
    • With Templates: Using Resend-hosted templates.
    • With React Email: Using React component templates (available in Next.js examples).
    • Scheduled Send: Scheduling email delivery for a future time.

    Forms & Server Actions

    • Contact Form: Implementing batch sends with confirmation and notifications.

    Receiving Emails

    • Inbound Webhooks: Receiving and forwarding incoming emails.
    • Webhook Verification: Validating webhook signatures for security.

    Management

    • Audiences: Managing contacts and segments.
    • Domains: Creating and verifying domains.

    Advanced

    • Authentication: Email verification using better-auth.
    • Prevent Threading: Techniques to stop Gmail from grouping emails into conversations.
  6. Project structure for SvelteKit + Resend

    main

    The project is organized into the following structure to separate Resend logic from UI components and routing:

    • src/lib/server/resend.ts: Contains the Resend client initialization.
    • src/lib/components/: Reusable UI components like PageHeader.svelte and ResultDisplay.svelte.
    • src/routes/: Defines the application routes:
      • api/: Contains API route handlers for various email operations (e.g., send/, send-attachment/).
      • send-email/, attachments/, etc.: Dedicated pages for demonstrating specific Resend features.
    src/
      lib/
        server/
          resend.ts      # Resend client initialization
        components/
          PageHeader.svelte
          ResultDisplay.svelte
      routes/
        +layout.svelte    # Navigation layout
        +page.svelte      # Home page
        api/              # API route handlers
          send/           # Send email endpoint
          send-attachment/ # Attachment endpoint
          ...
        send-email/       # Send email page
        attachments/       # Attachments page
        ...
  7. Project structure for Next.js Resend examples

    main

    The project is organized as follows:

    • src/app/api/: Contains API routes for email sending logic.
    • src/app/contact-form/: Example of a Server Action implementation.
    • src/app/send-email/: UI for basic email sending.
    • src/app/automations/: UI for managing automations.
    • src/components/: Shared UI components.
    • src/emails/: React Email templates.
    • src/lib/resend.js: The Resend client configuration.
    src/
    ├── app/
    │   ├── api/                  # API routes
    │   ├── contact-form/         # Server Action example
    │   ├── send-email/           # Basic send UI
    │   ├── automations/          # Automations UI
    │   └── ...                  # Other examples
    ├── components/               # Shared UI components
    ├── emails/                   # React Email templates
    └── lib/
        └── resend.js             # Resend client
  8. Integrate Resend with Flask, FastAPI, or Django

    main

    The repository provides boilerplate applications for common Python web frameworks to demonstrate how to trigger emails via HTTP requests.

    Flask

    1. Run the app: python examples/flask_app.py
    2. Send a request:
    curl -X POST http://localhost:5000/send \
      -H "Content-Type: application/json" \
      -d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from Flask!"}'

    FastAPI

    1. Run the app: python examples/fastapi_app.py
    2. Send a request:
    curl -X POST http://localhost:8000/send \
      -H "Content-Type: application/json" \
      -d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from FastAPI!"}'

    Django

    1. Navigate to the app: cd django_app
    2. Install Django: pip install django
    3. Run the server: python manage.py runserver 8001
    4. Send a request:
    curl -X POST http://localhost:8001/send \
      -H "Content-Type: application/json" \
      -d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from Django!"}'
    # Example: Testing the Flask endpoint
    curl -X POST http://localhost:5000/send \
      -H "Content-Type: application/json" \
      -d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from Flask!"}'
  9. Run Resend Rust examples via Cargo

    main

    The repository contains numerous pre-configured examples that can be run directly using cargo run --example <name>.

    Available examples include:

    • basic_send: Simple email sending
    • batch_send: Multiple emails at once
    • with_attachments: Emails with files
    • with_cid_attachments: Inline images (CID)
    • scheduled_send: Future delivery
    • with_template: Using Resend templates
    • prevent_threading: Prevent Gmail threading
    • audiences: Manage contacts
    • domains: Manage domains
    • automations: Manage automations
    • metrics: Email metrics (totals, period, broadcast)
    • inbound: Handle inbound emails
    • double_optin_subscribe: Create contact + send confirmation
    • double_optin_webhook: Process confirmation click
    # Example: Run the basic email sending example
    cargo run --example basic_send
    
    # Example: Run the batch sending example
    cargo run --example batch_send
  10. Run Java Resend examples via Maven

    main

    You can run specific example classes using the mvn exec:java command by specifying the exec.mainClass.

    Available examples include:

    • Basic Email Sending: com.resend.examples.BasicSend
    • Batch Sending: com.resend.examples.BatchSend
    • With Attachments: com.resend.examples.WithAttachments
    • With CID (Inline) Attachments: com.resend.examples.WithCidAttachments
    • Scheduled Sending: com.resend.examples.ScheduledSend
    • Using Templates: com.resend.examples.WithTemplate
    • Prevent Gmail Threading: com.resend.examples.PreventThreading
    • Audiences & Contacts: com.resend.examples.Audiences
    • Domain Management: com.resend.examples.Domains
    • Automations: com.resend.examples.Automations
    • Metrics: com.resend.examples.Metrics
    • Inbound Email: com.resend.examples.Inbound
    • Double Opt-In (Subscribe): com.resend.examples.DoubleOptinSubscribe
    # Example: Running Basic Email Sending
    mvn compile exec:java -Dexec.mainClass="com.resend.examples.BasicSend"
    
    # Example: Running Double Opt-In Subscription
    mvn compile exec:java -Dexec.mainClass="com.resend.examples.DoubleOptinSubscribe" -Dexec.args="user@example.com John"