|
| 1 | +--- |
| 2 | ++title: 'Send (& receive) emails using Inbound' |
| 3 | +sidebarTitle: 'Inbound' |
| 4 | ++description: 'Learn how to send and receive emails using React Email and the Inbound 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/components](https://www.npmjs.com/package/@react-email/components) package and the [Inbound Node.js SDK](https://www.npmjs.com/package/inboundemail). |
| 11 | + |
| 12 | +Make sure you have an account on [inbound](https://inbound.new?utm_source=react-email%20docs&utm_medium=email&utm_campaign=react_email_campaign), you will need an inbound API key. |
| 13 | + |
| 14 | +<CodeGroup> |
| 15 | + |
| 16 | +```sh npm |
| 17 | +npm install inboundemail @react-email/components |
| 18 | +``` |
| 19 | + |
| 20 | +```sh yarn |
| 21 | +yarn add inboundemail @react-email/components |
| 22 | +``` |
| 23 | + |
| 24 | +```sh pnpm |
| 25 | +pnpm add inboundemail @react-email/components |
| 26 | +``` |
| 27 | + |
| 28 | +```sh bun |
| 29 | +bun add inboundemail @react-email/components |
| 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 * as React from 'react'; |
| 40 | +import { Html, Button } from "@react-email/components"; |
| 41 | + |
| 42 | +export function Email(props) { |
| 43 | + const { url } = props; |
| 44 | + |
| 45 | + return ( |
| 46 | + <Html lang="en"> |
| 47 | + <Button href={url}>Click me</Button> |
| 48 | + </Html> |
| 49 | + ); |
| 50 | +} |
| 51 | + |
| 52 | +export default Email; |
| 53 | +``` |
| 54 | + |
| 55 | +## 3. Send email |
| 56 | + |
| 57 | +<Info>When integrating with other services, you need to convert your React template into HTML before sending. Inbound takes care of that for you. You can just directly pass the React template to the SDK.</Info> |
| 58 | + |
| 59 | +Import the email template you just built and use the Inbound SDK to send it. |
| 60 | + |
| 61 | +```tsx |
| 62 | +import { Inbound } from 'inboundemail'; |
| 63 | +import { Email } from './email'; |
| 64 | + |
| 65 | +const inbound = new Inbound(process.env.INBOUND_API_KEY); |
| 66 | + |
| 67 | +await inbound.emails.send({ |
| 68 | + from: 'you@example.com', |
| 69 | + to: 'user@gmail.com', |
| 70 | + subject: 'hello world', |
| 71 | + react: <Email url="https://example.com" />, |
| 72 | +}); |
| 73 | +``` |
| 74 | + |
| 75 | +## 4. Reply to an email |
| 76 | + |
| 77 | +Use the Inbound SDK to reply to an email with the same template you just created. |
| 78 | + |
| 79 | +```tsx |
| 80 | +import { Inbound } from 'inboundemail'; |
| 81 | +import { Email } from './email'; |
| 82 | + |
| 83 | +const inbound = new Inbound({ |
| 84 | + apiKey: process.env.INBOUND_API_KEY |
| 85 | +}); |
| 86 | + |
| 87 | +// sending an email via inbound |
| 88 | +await inbound.emails.send(email.id,{ |
| 89 | + from: "React Email <react.email@inbound.new>", |
| 90 | + react: <Email url="https://example.com" /> |
| 91 | +}); |
| 92 | + |
| 93 | +// replying to an email that was received via inbound |
| 94 | +await inbound.emails.reply(email.id,{ |
| 95 | + from: "React Email <react.email@inbound.new>", |
| 96 | + react: <Email url="https://example.com" /> |
| 97 | +}); |
| 98 | + |
| 99 | + |
| 100 | +``` |
| 101 | + |
| 102 | +## Try it yourself |
| 103 | + |
| 104 | +<Card |
| 105 | + title="Get started on Inbound" |
| 106 | + icon='arrow-up-right-from-square' |
| 107 | + iconType="duotone" |
| 108 | + href="https://inbound.new?utm_source=react-email%20docs&utm_medium=email&utm_campaign=react_email_campaign" |
| 109 | +> |
| 110 | + See it on our examples. |
| 111 | +</Card> |
0 commit comments