> = ({
8 | firstName,
9 | }) => (
10 |
11 |
Welcome, {firstName}!
12 |
13 | );
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-nextjs-typescript",
3 | "private": true,
4 | "scripts": {
5 | "dev": "next dev"
6 | },
7 | "dependencies": {
8 | "next": "latest",
9 | "react": "latest",
10 | "react-dom": "latest",
11 | "resend": "latest"
12 | },
13 | "devDependencies": {
14 | "@types/node": "latest",
15 | "@types/react": "latest",
16 | "typescript": "latest"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "strict": false,
12 | "forceConsistentCasingInFileNames": true,
13 | "noEmit": true,
14 | "incremental": true,
15 | "esModuleInterop": true,
16 | "module": "esnext",
17 | "resolveJsonModule": true,
18 | "moduleResolution": "node",
19 | "isolatedModules": true,
20 | "jsx": "preserve"
21 | },
22 | "include": [
23 | "next-env.d.ts",
24 | "**/*.ts",
25 | "**/*.tsx"
26 | ],
27 | "exclude": [
28 | "node_modules"
29 | ]
30 | }
31 |
--------------------------------------------------------------------------------
/pages/api/send.ts:
--------------------------------------------------------------------------------
1 | import type { NextApiRequest, NextApiResponse } from 'next';
2 | import { EmailTemplate } from '../../components/email-template';
3 | import { Resend } from 'resend';
4 |
5 | const resend = new Resend(process.env.RESEND_API_KEY);
6 |
7 | export default async (req: NextApiRequest, res: NextApiResponse) => {
8 | try {
9 | const { data, error } = await resend.emails.send({
10 | from: 'Acme ',
11 | to: ['delivered@resend.dev'],
12 | subject: 'Hello world',
13 | react: EmailTemplate({ firstName: 'John' }),
14 | });
15 |
16 | if (error) {
17 | res.status(400).json({ error });
18 | }
19 |
20 | res.status(200).json({ data });
21 | } catch (error) {
22 | res.status(400).json({ error });
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Resend with Next.js (Pages Router)
2 |
3 | This example shows how to use Resend with [Next.js](https://nextjs.org).
4 |
5 | ## Deploy your own
6 |
7 | Deploy the example using [Vercel](https://vercel.com):
8 |
9 | [](https://vercel.com/new/clone?repository-url=https://github.com/resend/resend-nextjs-pages-router-example&project-name=resend-nextjs-pages-router-example&repository-name=resend-nextjs-pages-router-example&env=RESEND_API_KEY)
10 |
11 | ## Instructions
12 |
13 | 1. Define environment variables in `.env` file.
14 |
15 | ```sh
16 | cp .env.example .env
17 | ```
18 |
19 | 2. Install dependencies:
20 |
21 | ```sh
22 | npm install
23 | # or
24 | yarn
25 | ```
26 |
27 | 3. Run Next.js locally:
28 |
29 | ```sh
30 | npm run dev
31 | ```
32 |
33 | 4. Open URL in the browser:
34 |
35 | ```
36 | http://localhost:3000/api/send
37 | ```
38 |
39 | ## License
40 |
41 | MIT License
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Plus Five Five, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------