-
Notifications
You must be signed in to change notification settings - Fork 945
feat(integrations): add Azure Communication Email integration example #3102
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
base: canary
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| title: 'Send email using Azure Communication Email' | ||
| sidebarTitle: 'Azure Communication Email' | ||
| description: 'Learn how to send an email using React Email and the Azure Communication Email SDK.' | ||
| 'og:image': 'https://react.email/static/covers/react-email.png' | ||
| --- | ||
|
|
||
| ## 1. Install dependencies | ||
|
|
||
| Get the [@react-email/components](https://www.npmjs.com/package/@react-email/components) package and the [Azure Communication Email SDK](https://www.npmjs.com/package/@azure/communication-email). | ||
|
|
||
| <CodeGroup> | ||
|
|
||
| ```sh npm | ||
| npm install @azure/communication-email @react-email/components | ||
| ``` | ||
|
|
||
| ```sh yarn | ||
| yarn add @azure/communication-email @react-email/components | ||
| ``` | ||
|
|
||
| ```sh pnpm | ||
| pnpm add @azure/communication-email @react-email/components | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| ## 2. Create an email using React | ||
|
|
||
| Start by building your email template in a `.jsx` or `.tsx` file. | ||
|
|
||
| ```tsx email.tsx | ||
| import * as React from 'react'; | ||
| import { Html, Button } from "@react-email/components"; | ||
|
|
||
| export function Email(props) { | ||
| const { url } = props; | ||
|
|
||
| return ( | ||
| <Html lang="en"> | ||
| <Button href={url}>Click me</Button> | ||
| </Html> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## 3. Convert to HTML and send email | ||
|
|
||
| Import the email template you just built, convert into an HTML string, and use the Azure Communication Email SDK to send it. | ||
|
|
||
| ```tsx | ||
| import { EmailClient } from '@azure/communication-email'; | ||
| import { render } from '@react-email/components'; | ||
| import { Email } from './email'; | ||
|
|
||
| const client = new EmailClient(process.env.AZURE_EMAIL_CONNECTION_STRING); | ||
|
|
||
| const from ='you@example.com'; | ||
| const emailHtml = await render(<Email url="https://example.com" />); | ||
|
|
||
| const message = { | ||
| senderAddress: from, | ||
| content: { | ||
| subject: 'hello world', | ||
| html: emailHtml, | ||
| }, | ||
| recipients: { | ||
| to: [{ address: 'user@gmail.com' }], | ||
| }, | ||
| }; | ||
|
|
||
| const poller = await client.beginSend(message); | ||
|
|
||
| await poller.pollUntilDone(); | ||
| ``` | ||
|
|
||
| <Info>Azure Communication Email expects the sender in the `senderAddress` field.</Info> | ||
|
|
||
| ## Try it yourself | ||
|
|
||
| <Card | ||
| title="Azure Communication Email example" | ||
| icon='arrow-up-right-from-square' | ||
| iconType="duotone" | ||
| href="https://github.com/resend/react-email/tree/main/examples/azure-communication-email" | ||
| > | ||
| See the full source code. | ||
| </Card> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "name": "react-email-with-azure-communication-email", | ||
| "license": "MIT", | ||
| "private": true, | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "main": "./dist/index.js", | ||
| "files": [ | ||
| "dist/**" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsdown src/index.tsx --format esm --target node20", | ||
| "dev": "tsdown src/index.tsx --format esm --target node20 --watch", | ||
| "clean": "rm -rf dist" | ||
| }, | ||
| "dependencies": { | ||
| "@azure/communication-email": "^1", | ||
| "@react-email/components": "catalog:", | ||
| "react": "catalog:", | ||
| "react-dom": "catalog:" | ||
| }, | ||
| "devDependencies": { | ||
| "tsdown": "catalog:", | ||
| "typescript": "catalog:" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Button, Html } from '@react-email/components'; | ||
|
|
||
| interface EmailProps { | ||
| url: string; | ||
| } | ||
|
|
||
| export const Email: React.FC<Readonly<EmailProps>> = ({ url }) => { | ||
| return ( | ||
| <Html lang="en"> | ||
| <Button href={url}>Click me</Button> | ||
| </Html> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { EmailClient } from '@azure/communication-email'; | ||
| import { render } from '@react-email/components'; | ||
| import { Email } from './email'; | ||
|
|
||
| const client = new EmailClient(process.env.AZURE_EMAIL_CONNECTION_STRING); | ||
|
|
||
| const from = 'you@example.com'; | ||
| const emailHtml = await render(<Email url="https://example.com" />); | ||
|
|
||
| const message = { | ||
| senderAddress: from, | ||
| content: { | ||
| subject: 'hello world', | ||
| html: emailHtml, | ||
| }, | ||
| recipients: { | ||
| to: [{ address: 'user@gmail.com' }], | ||
| }, | ||
| }; | ||
|
|
||
| const poller = await client.beginSend(message); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Custom agent: API Key Permission Check SDK Methods This change adds a new Azure Communication Email send operation ( Prompt for AI agents |
||
|
|
||
| await poller.pollUntilDone(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "composite": false, | ||
| "declaration": true, | ||
| "declarationMap": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "inlineSources": false, | ||
| "isolatedModules": true, | ||
| "moduleResolution": "node", | ||
| "noUnusedLocals": false, | ||
| "noUnusedParameters": false, | ||
| "preserveWatchOutput": true, | ||
| "skipLibCheck": true, | ||
| "strict": true, | ||
| "strictNullChecks": true, | ||
| "jsx": "react-jsx", | ||
| "lib": ["ESNext", "DOM", "DOM.Iterable"], | ||
| "module": "ESNext", | ||
| "target": "ESNext", | ||
| "types": ["vitest/globals"] | ||
| }, | ||
| "include": ["."], | ||
| "exclude": ["dist", "build", "node_modules"] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Custom agent: API Key Permission Check SDK Methods
This new Azure SDK send flow (
beginSend) is documented without a required permission check for production credentials. Add an explicit note to verify theAZURE_EMAIL_CONNECTION_STRINGhas email-send permissions before deployment (API Key Permission Check SDK Methods rule).Prompt for AI agents