Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update according to changes on the docs #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Get the Resend Node.js SDK.
npm install resend
```

</CodeGroup>

### 2. Create an email template

Start by creating your email template on `src/emails/email-template.tsx`:
Expand Down Expand Up @@ -50,27 +48,24 @@ Change the file extension of the worker's main file to `tsx` and modify your con
After that, you can send your email using the `react` parameter:

```tsx
import * as React from 'react';
import { Resend } from 'resend';
import { EmailTemplate } from './emails/email-template';

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
async fetch(request, env, context): Promise<Response> {
const resend = new Resend('re_123456789');

const data = await resend.emails.send({
from: 'Acme <[email protected]>',
to: ['[email protected]'],
subject: 'hello world',
react: <EmailTemplate firstName="John" />,
}):

return new Response(JSON.stringify(data), {
headers: {
'Content-Type': 'application/json',
},
});

return Response.json(data);
},
};
} satisfies ExportedHandler<Env, ExecutionContext>;
```

### 4. Deploy and send email
Expand Down
13 changes: 5 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { Resend } from 'resend';
import { EmailTemplate } from './emails/email-template';

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const resend = new Resend('re_123456789'/* env.RESEND_API_KEY */);
async fetch(request, env, context): Promise<Response> {
const resend = new Resend('re_123456789' /* env.RESEND_API_KEY */);

const data = await resend.emails.send({
from: 'Acme <[email protected]>',
Expand All @@ -12,10 +13,6 @@ export default {
react: <EmailTemplate firstName="John" />,
});

return new Response(JSON.stringify(data), {
headers: {
'Content-Type': 'application/json',
},
});
return Response.json(data);
},
};
} satisfies ExportedHandler<Env, ExecutionContext>;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* Language and Environment */
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
"jsx": "react" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
Expand Down