Skip to main content
Receiving emails contain the HTML and Plain Text body of the email, as well as the headers.
Webhooks do not include the email body, headers, or attachments, only their metadata. You must call the Received emails API or the Attachments API to retrieve them. This design choice supports large attachments in serverless environments that have limited request body sizes.
After receiving the webhook event, call the Receiving API. Here are some examples:
// app/api/events/route.ts
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
import { Resend } from 'resend';

const resend = new Resend('re_xxxxxxxxx');

export const POST = async (request: NextRequest) => {
  const event = await request.json();

  if (event.type === 'email.received') {
    const { data: email } = await resend.emails.receiving.get(
      event.data.email_id,
    );

    console.log(email.html);
    console.log(email.text);
    console.log(email.headers);

    return NextResponse.json(email);
  }

  return NextResponse.json({});
};
// routes/api.php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
use Resend\Laravel\Facades\Resend;

Route::post('/events', function (Request $request) {
    $event = $request->json()->all();

    if ($event['type'] === 'email.received') {
        $email = Resend::emails()->receiving->get($event['data']['email_id']);

        Log::info($email->html);
        Log::info($email->text);
        Log::info($email->headers);

        return response()->json($email);
    }

    return response()->json([]);
});
// index.php
// Include Composer autoload file to load Resend SDK classes...
require __DIR__ . '/vendor/autoload.php';

header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['error' => 'Method Not Allowed']);
    exit;
}

$body = file_get_contents('php://input');
$event = json_decode($body, true);

if (json_last_error() !== JSON_ERROR_NONE) {
    http_response_code(400);
    echo json_encode(['error' => 'Invalid JSON']);
    exit;
}

if ($event['type'] === 'email.received') {
    $resend = Resend::client('re_xxxxxxxxx');

    $email = $resend->emails->receiving->get($event['data']['email_id']);

    echo json_encode($email);
    exit;
}

echo json_encode([]);
use axum::{extract::State, response::Json};
use resend_rs::Resend;
use std::sync::Arc;

#[derive(Serialize)]
struct Empty {}

async fn example(
    State(state): State<Arc<AppState>>,
    Json(event): Json<resend_rs::events::EmailEvent>,
) -> Response {
    if matches!(
        event.r#type,
        resend_rs::events::EmailEventType::EmailReceived
    ) {
        let email = state
            .resend
            .receiving
            .get(&event.data.email_id)
            .await
            .unwrap();

        dbg!(&email.html, &email.text, &email.headers);

        Json(email).into_response()
    } else {
        Json(Empty {}).into_response()
    }
}