|
| 1 | +--- |
| 2 | +title: "Send email using Sendora" |
| 3 | +sidebarTitle: "Sendora" |
| 4 | +description: "Learn how to send an email using React Email and the Sendora Node.js SDK." |
| 5 | +"og:image": "https://react.email/static/covers/react-email.png" |
| 6 | +--- |
| 7 | + |
| 8 | +## 1. Install dependencies |
| 9 | + |
| 10 | +Get the [react-email](https://www.npmjs.com/package/react-email) package and the [Sendora Node.js SDK](https://www.npmjs.com/package/@sendora/sdk). |
| 11 | + |
| 12 | +Make sure you have an account on [Sendora](https://sendorahq.com), you will need a server key and a verified sending domain. |
| 13 | + |
| 14 | +<CodeGroup> |
| 15 | + |
| 16 | +```sh npm |
| 17 | +npm install @sendora/sdk react-email |
| 18 | +``` |
| 19 | + |
| 20 | +```sh yarn |
| 21 | +yarn add @sendora/sdk react-email |
| 22 | +``` |
| 23 | + |
| 24 | +```sh pnpm |
| 25 | +pnpm add @sendora/sdk react-email |
| 26 | +``` |
| 27 | + |
| 28 | +```sh bun |
| 29 | +bun add @sendora/sdk react-email |
| 30 | +``` |
| 31 | + |
| 32 | +</CodeGroup> |
| 33 | + |
| 34 | +## 2. Create an email using React |
| 35 | + |
| 36 | +Start by building your email template in a `.jsx` or `.tsx` file. |
| 37 | + |
| 38 | +```tsx email.tsx |
| 39 | +import { Button, Html } from "react-email"; |
| 40 | + |
| 41 | +interface EmailProps { |
| 42 | + url: string; |
| 43 | +} |
| 44 | + |
| 45 | +export function Email({ url }: EmailProps) { |
| 46 | + return ( |
| 47 | + <Html lang="en"> |
| 48 | + <Button href={url}>Click me</Button> |
| 49 | + </Html> |
| 50 | + ); |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +## 3. Convert to HTML and send email |
| 55 | + |
| 56 | +Import the email template you just built, convert it into HTML and plain text, and use the Sendora SDK to send both. |
| 57 | + |
| 58 | +<Info>While you develop, use the key of a Sendora test server. Sendora checks and logs each email sent with it, but delivers none.</Info> |
| 59 | + |
| 60 | +```tsx |
| 61 | +import { Sendora } from "@sendora/sdk"; |
| 62 | +import { render, toPlainText } from "react-email"; |
| 63 | +import { Email } from "./email"; |
| 64 | + |
| 65 | +const sendora = new Sendora({ token: process.env.SENDORA_API_TOKEN }); |
| 66 | + |
| 67 | +const html = await render(<Email url="https://example.com" />); |
| 68 | + |
| 69 | +await sendora.email.send({ |
| 70 | + from: "you@example.com", |
| 71 | + to: ["user@gmail.com"], |
| 72 | + subject: "hello world", |
| 73 | + html, |
| 74 | + text: toPlainText(html), |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +## Try it yourself |
| 79 | + |
| 80 | +<Card |
| 81 | + title="Sendora example" |
| 82 | + icon="arrow-up-right-from-square" |
| 83 | + iconType="duotone" |
| 84 | + href="https://github.com/resend/react-email/tree/main/examples/sendora" |
| 85 | +> |
| 86 | + See the full source code. |
| 87 | +</Card> |
0 commit comments