Skip to content

Commit 33c4bba

Browse files
authored
feat: renovated with-attachments example (#193)
1 parent 049fcbb commit 33c4bba

File tree

14 files changed

+85
-3387
lines changed

14 files changed

+85
-3387
lines changed

with-attachments/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RESEND_API_KEY=re_xxxxxxxxxxxx

with-attachments/.eslintrc.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

with-attachments/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# next.js
2+
.env*
3+
.next
4+
next-env.d.ts
5+
/.next/
6+
/out/
7+
8+
# dependencies
9+
/node_modules
10+
/.pnp
11+
.pnp.*
12+
.yarn/*
13+
!.yarn/patches
14+
!.yarn/plugins
15+
!.yarn/releases
16+
!.yarn/versions
17+
18+
# env files (can opt-in for committing if needed)
19+
.env*
20+
!.env.example
21+
22+
# misc
23+
.DS_Store
24+
*.pem
25+
26+
# typescript
27+
*.tsbuildinfo
28+
next-env.d.ts

with-attachments/.prettierignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

with-attachments/.prettierrc.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { resend } from '../../../lib/resend';
2+
3+
export async function POST() {
4+
const response = await resend.emails.send({
5+
from: 'Acme <[email protected]>',
6+
7+
subject: 'Receipt for your payment',
8+
html: '<p>Thanks for the payment</p>',
9+
attachments: [
10+
{
11+
path: 'https://resend.com/static/sample/invoice.pdf',
12+
filename: 'sample-invoice.pdf',
13+
},
14+
],
15+
});
16+
17+
return Response.json(response, {
18+
status: response.error ? 500 : 200,
19+
});
20+
}

with-attachments/lib/resend.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Resend } from 'resend';
2+
3+
export const resend = new Resend(process.env.RESEND_API_KEY);

with-attachments/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

with-attachments/package.json

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66
"scripts": {
77
"build": "next build",
88
"dev": "next dev",
9-
"start": "next start",
10-
"lint": "eslint --fix --ext .ts ./src",
11-
"format": "prettier --write ."
9+
"start": "next start"
1210
},
1311
"dependencies": {
14-
"next": "14.2.30",
15-
"react": "18.3.1",
16-
"react-dom": "18.3.1",
17-
"resend": "latest"
12+
"next": "16.0.3",
13+
"react": "19.2.0",
14+
"react-dom": "19.2.0",
15+
"resend": "6.5.2"
1816
},
1917
"devDependencies": {
20-
"@types/node": "20.11.20",
21-
"@types/react": "18.3.27",
22-
"@types/react-dom": "18.3.7",
23-
"@typescript-eslint/eslint-plugin": "7.1.0",
24-
"eslint": "8.56.0",
25-
"eslint-config-next": "14.1.1",
26-
"prettier": "3.2.5",
27-
"typescript": "5.3.3"
18+
"@types/node": "24.10.1",
19+
"@types/react": "19.2.6",
20+
"@types/react-dom": "19.2.3",
21+
"typescript": "5.9.3"
2822
}
2923
}

with-attachments/readme.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This example show how to send Resend emails with attachments.
77
### 1. Install the dependencies
88

99
```bash
10-
yarn dev
10+
yarn install
1111
```
1212

1313
### 2. Create a `.env` file at the root and add your Resend API
@@ -22,28 +22,26 @@ RESEND_API_KEY=re_8m9gwsVG_6n94KaJkJ42Yj6qSeVvLq9xF
2222
yarn dev
2323
```
2424

25-
### 4. Update the `from` and `to` in the `send.ts`
25+
### 4. Update the `from` and `to` in the `app/api/send/route.ts`
2626

27-
You can update the `from` and `to` here so send from your own domain and to your email address. The `to` must be a verified `domain` in your account.
27+
You can update the `from` and `to` here so sending is done from your own domain and to your email address. The `to` must be a verified domain in your account.
2828

2929
```tsx
3030
const data = await resend.emails.send({
31-
32-
33-
subject: 'Receipt for Your Payment',
31+
from: 'Acme <[email protected]>',
32+
33+
subject: 'Receipt for your payment',
34+
html: '<p>Thanks for the payment</p>',
3435
attachments: [
3536
{
36-
content: invoiceBuffer,
37-
path: 'path/to/file/invoice.pdf',
38-
filename: 'invoice.pdf',
37+
path: 'https://acme.com/static/sample/invoice.pdf',
38+
filename: 'sample-invoice.pdf',
3939
},
4040
],
41-
html: '<h1>Thanks for the payment</h1>',
42-
text: 'Thanks for the payment',
4341
});
4442
```
4543

46-
### 4. Send a POST request to `/api/send`
44+
### 5. Send a POST request to `/api/send`
4745

4846
```bash
4947
curl --location --request POST 'http://localhost:3000/api/send'

0 commit comments

Comments
 (0)