Documentation Index
Fetch the complete documentation index at: https://resend.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
A common use case for Receiving emails is to process attachments.
Webhooks do not include the actual content of attachments, only their
metadata. You must call the Attachments
API to retrieve the
content. This design choice supports large attachments in serverless
environments that have limited request body sizes.
Users can forward airplane tickets, receipts, and expenses to you. Then, you can extract key information from attachments and use that data.
To do this, call the Attachments API after receiving the webhook event. That API will return a list of attachments with their metadata and a download_url that you can use to download the actual content.
Note that the download_url is valid for 1 hour. After that, you will need to call the
Attachments API
again to get a new download_url. You can also check the expires_at field on
each attachment to see exactly when it will expire.
Here’s how you can implement this:
// 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: attachments } =
await resend.emails.receiving.attachments.list({
emailId: event.data.email_id,
});
for (const attachment of attachments) {
// use the download_url to download attachments however you want
const response = await fetch(attachment.download_url);
if (!response.ok) {
console.error(`Failed to download ${attachment.filename}`);
continue;
}
// get the file's contents
const buffer = Buffer.from(await response.arrayBuffer());
// process the content (e.g., save to storage, analyze, etc.)
}
return NextResponse.json({ attachmentsProcessed: attachments.length });
}
return NextResponse.json({});
};
Once you process attachments, you may want to forward the email to another address. Learn more about forwarding emails.