-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Usage page init * Add resend version of usage * dual resend and nodemailer content * few more touches * Fixing and improving content * formatting * finetune * Add Ul mdx element stylings * Improve integrations texts * fix mdx styling * Make usage steps more real world
- Loading branch information
Showing
9 changed files
with
267 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { TabbedCode, TabbedCodeItem } from "@components/Code"; | ||
import { getContentEmail } from "@components/MdxComponents/utils"; | ||
|
||
export type ComponentSourceTabsProps = { | ||
emailId: string; | ||
}; | ||
|
||
export const EmailSourceTabs = async ({ | ||
emailId, | ||
}: ComponentSourceTabsProps) => { | ||
const emailSource = await getContentEmail(emailId); | ||
|
||
const tabs: TabbedCodeItem[] = [ | ||
{ | ||
id: `${emailSource.id}.tsx`, | ||
htmlCode: emailSource.source, | ||
}, | ||
]; | ||
return ( | ||
<div className="relative overflow-hidden rounded-md"> | ||
<TabbedCode | ||
tabs={tabs} | ||
collapsedClassName="max-h-[350px]" | ||
className="min-h-[350px]" | ||
></TabbedCode> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { EmailSourceTabs } from "src/docs/components/MdxComponents"; | ||
|
||
import { | ||
Tabs, | ||
TabsContent, | ||
TabsList, | ||
TabsTrigger, | ||
} from "@components/Tabs/Tabs"; | ||
|
||
# Usage | ||
|
||
As **MailingUI** is collection of email components developed on top of [react-email](https://react.email) library, it also utilize its rendering capabilities to efficiently generate accurate HTML markup that is optimized for various email clients. Once the HTML markup is rendered, you have the flexibility to employ any preferred email sending service or library to effectively deliver your emails. | ||
|
||
Usually you would use Javascript integration of email providers to send emails from your application. In this quick guide, we'll illustrate how to use **MailingUI** with [Resend](https://resend.com/) and [Nodemailer](https://nodemailer.com) providers. For alternative providers, please refer to their documentation or explore [Usefull links section](/docs/usage#usefull-links) for more information. | ||
|
||
## 1. Install dependencies | ||
|
||
For **MailingUI** install [see Installation section](/docs/installation). | ||
|
||
<Tabs defaultValue="resend"> | ||
<div className="flex items-center justify-start w-full mb-8"> | ||
<TabsList className="rounded-2xl"> | ||
<TabsTrigger value="resend" className="px-7 py-2 rounded-[10px]">Using Resend</TabsTrigger> | ||
<TabsTrigger value="nodemailer" className="px-7 py-2 rounded-[10px]">Using Nodemailer</TabsTrigger> | ||
</TabsList> | ||
</div> | ||
|
||
<TabsContent value="resend"> | ||
```bash | ||
npm install resend | ||
``` | ||
</TabsContent> | ||
<TabsContent value="nodemailer"> | ||
```bash | ||
npm install nodemailer | ||
``` | ||
</TabsContent> | ||
</Tabs> | ||
|
||
## 2. Create email template | ||
|
||
You can use both **MailingUI** components installed and and any other _react-email_ components to create email template. For example: | ||
|
||
<EmailSourceTabs emailId="hello-world" /> | ||
|
||
## 3. Send email | ||
|
||
Usually you would place email integration on server side of your Next.js application like API route handler or similar. Our example uses Next.js app router _route handlers_ to send email. | ||
|
||
<Tabs defaultValue="resend"> | ||
<div className="flex items-center justify-start w-full mb-8"> | ||
<TabsList className="rounded-2xl"> | ||
<TabsTrigger value="resend" className="px-7 py-2 rounded-[10px]">Using Resend</TabsTrigger> | ||
<TabsTrigger value="nodemailer" className="px-7 py-2 rounded-[10px]">Using Nodemailer</TabsTrigger> | ||
</TabsList> | ||
</div> | ||
|
||
<TabsContent value="resend"> | ||
Given _Resend_ is operated by same team as _react-email_, email rendering is built-in in _Resend's SDK_. Thus you can use its sendEmail method directly. | ||
<br/> | ||
|
||
```ts | ||
import { NextResponse } from 'next/server'; | ||
import { Resend } from "resend"; | ||
import HelloWorldEmail from "@/emails/test"; | ||
|
||
const resend = new Resend(process.env.RESEND_API_KEY); | ||
|
||
export async function POST() { | ||
try { | ||
const data = await resend.emails.send({ | ||
from: process.env.RESEND_SENDER, | ||
to: "user@email.com", | ||
subject: "hello world", | ||
react: HelloWorldEmail({farewellMessage: "Goodbye from MailingUI team!"}), | ||
}); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
return NextResponse.json({ error }); | ||
} | ||
} | ||
``` | ||
|
||
</TabsContent> | ||
<TabsContent value="nodemailer"> | ||
With Nodemailer (and generally most others providers) you need to render email template first and then send it with provider's API. | ||
<br/> | ||
|
||
```ts | ||
import { NextResponse } from 'next/server'; | ||
import { render } from "@react-email/render"; | ||
import Nodemailer from "nodemailer"; | ||
import HelloWorldEmail from "@/emails/test"; | ||
|
||
const nodemailer = Nodemailer.createTransport({ | ||
host: process.env.NODEMAILER_HOST, | ||
port: 465, | ||
secure: true, | ||
auth: { | ||
user: process.env.NODEMAILER_USER, | ||
pass: process.env.NODEMAILER_PASS, | ||
}, | ||
}); | ||
|
||
export async function POST() { | ||
try { | ||
const emailHtml = render(HelloWorldEmail({ | ||
farewellMessage: "Goodbye from MailingUI team!" | ||
})); | ||
const data = await nodemailer.sendMail({ | ||
from: process.env.NODEMAILER_SENDER, | ||
to: "user@email.com", | ||
subject: "hello world", | ||
html: emailHtml, | ||
}); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
return NextResponse.json({ error }); | ||
} | ||
} | ||
``` | ||
|
||
</TabsContent> | ||
</Tabs> | ||
|
||
# Usefull links | ||
|
||
To gain a deeper understanding of how to utilize combination of _react-email_, _MailingUI_ components and email providers services, please refer to following resources: | ||
|
||
- [render utility](https://react.email/docs/utilities/render) - how to use render utility, with more examples (plain text etc.) | ||
- [react-email integrations](https://react.email/docs/integrations/overview) - other email sending services integrations, with _react-email_ examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Body, Container, Html, Row } from "@react-email/components"; | ||
import { Text } from "@mailingui/components"; | ||
|
||
type EmailProps = { | ||
welcomeMessage?: string; | ||
farewellMessage?: string; | ||
}; | ||
|
||
const HelloWorld = (props?: EmailProps) => { | ||
const { welcomeMessage, farewellMessage } = { | ||
welcomeMessage: "Hello World!", | ||
...props, | ||
}; | ||
return ( | ||
<Html> | ||
<Body style={main}> | ||
<Container style={container} width={600}> | ||
<Row style={{ marginBottom: "16px" }}> | ||
<Text style={{ fontSize: "32px" }}>{welcomeMessage}</Text> | ||
</Row> | ||
<Row> | ||
<Text> | ||
I am email written in React utilizing MailingUI components. | ||
</Text> | ||
</Row> | ||
{farewellMessage && ( | ||
<Row style={{ marginTop: "16px" }}> | ||
<Text>{farewellMessage}</Text> | ||
</Row> | ||
)} | ||
</Container> | ||
</Body> | ||
</Html> | ||
); | ||
}; | ||
export default HelloWorld; | ||
|
||
const main = { | ||
backgroundColor: "#f6f9fc", | ||
padding: "60px 0 122px 0", | ||
}; | ||
|
||
const container = { | ||
backgroundColor: "#ffffff", | ||
border: "1px solid #f0f0f0", | ||
padding: "40px", | ||
fontFamily: | ||
"'Inter', 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b1ec402
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.
Successfully deployed to the following URLs:
mailingui – ./
mailingui.vercel.app
mailingui-git-main-webscopeio.vercel.app
mailingui-webscopeio.vercel.app
mailingui.com