https://github.com/resend/resend-cloudflare-workers-example
This example shows how to use Resend with Cloudflare Workers
https://github.com/resend/resend-cloudflare-workers-example
Last synced: about 1 year ago
JSON representation
This example shows how to use Resend with Cloudflare Workers
- Host: GitHub
- URL: https://github.com/resend/resend-cloudflare-workers-example
- Owner: resend
- License: mit
- Created: 2023-06-02T18:11:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-12T23:45:16.000Z (about 1 year ago)
- Last Synced: 2025-04-13T05:45:52.730Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://resend.com/docs/send-with-cloudflare-workers
- Size: 68.4 KB
- Stars: 14
- Watchers: 1
- Forks: 7
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Resend with Cloudflare Workers
This example shows how to use Resend with [Cloudflare Workers](https://workers.cloudflare.com).
## Prerequisites
To get the most out of this guide, you’ll need to:
* [Create an API key](https://resend.com/api-keys)
* [Verify your domain](https://resend.com/domains)
## Instructions
### 1. Install
Get the Resend Node.js SDK.
```bash
npm install resend
```
### 2. Create an email template
Start by creating your email template on `src/emails/email-template.tsx`:
```tsx
import * as React from 'react';
interface EmailTemplateProps {
firstName: string;
}
export const EmailTemplate: React.FC> = ({
firstName,
}) => (
Welcome, {firstName}!
);
export default EmailTemplate;
```
### 3. Send the email using React and the SDK
Change the file extension of the worker's main file to `tsx` and modify your configurations.
After that, you can send your email using the `react` parameter:
```tsx
import { Resend } from 'resend';
import { EmailTemplate } from './emails/email-template';
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise {
const resend = new Resend('re_123456789');
const data = await resend.emails.send({
from: 'Acme ',
to: ['delivered@resend.dev'],
subject: 'hello world',
react: ,
}):
return new Response(JSON.stringify(data), {
headers: {
'Content-Type': 'application/json',
},
});
},
};
```
### 4. Deploy and send email
Run `wrangler deploy` and wait for it to finish. Once it's done, it will
give you a URL to try out, like `https://my-worker.your_name.workers.dev`,
that you can open and verify that your email has been sent.
## License
MIT License