react-mailto is a React component library designed to simplify the creation of mailto links with customizable headers and body content. This package allows you to generate fully-featured email links with options for specifying recipients, subject lines, C
npm install @slalombuild/react-mailto

react-mailto is a Mailto Link Generator library is a React utility for creating customizable mailto links with optional headers, such as subject, cc, bcc, and body. It also includes components for building the body content of the email with nested lists, line breaks, and indentation.
This package is ideal for developers who want to generate email links with rich content and customizable options directly within their React applications.
- Create Mailto Links: Easily generate mailto links with multiple recipients, subjects, CCs, and BCCs.
- Extract Body Content: Parse and format email body content from nested React components.
- Custom Components: Use components to handle email body formatting with support for indentation, line breaks, and lists.
To create a mailto link with a subject and body content, use the MailTo component. Here's a simple example:
`tsx
import React from 'react';
import { MailTo, MailToBody, MailToTrigger } from 'package-name';
const App = () => (
Hi there,
This is a test email.
Cheers,
Your Name
);
export default App;
`
For more complex scenarios, such as including CC and BCC recipients, or enabling link obfuscation, you can configure the Mailto component accordingly:
`tsx
import React from 'react';
import { MailTo, MailToBody, MailToTrigger } from 'package-name';
const App = () => (
subject="Meeting Invitation"
cc={["cc1@example.com", "cc2@example.com"]}
bcc={["bcc@example.com"]}
obfuscate
>
Dear Team,
Please join us for a meeting next week.
Regards,
Your Name
);
export default App;
`
The main component to generate the mailto link with optional headers and body content.
Props:
- to (string | string[]): Recipient email addresses.string
- subject (, optional): Subject of the email.string[] | string
- cc (, optional): CC recipients.string[] | string
- bcc (, optional): BCC recipients.boolean
- obfuscate (, optional): Whether to obfuscate the mailto link.React.ReactNode
- children (): Content to be rendered inside the link.
A component to define the body content of the email.
Props:
- children (React.ReactNode): Content to include in the email body.
A component that renders a clickable link to trigger the mailto action.
Props:
- children (React.ReactNode): The text or elements to display inside the link.props
- (React.AnchorHTMLAttributes, optional): Additional props for the anchor element.
A component to add indentation in the email body content.
Props:
- children (React.ReactNode): Content to include with indentation.spacing
- (number, optional): Number of spaces for indentation.
A component to insert line breaks in the email body content.
Props:
- spacing (number, optional): Number of line breaks.
We welcome contributions! If you want to help improve this package:
1. Fork the repository.
2. Create a new branch (git checkout -b feature/your-feature).git commit -am 'Add new feature'
3. Commit your changes ().git push origin feature/your-feature`).
4. Push to the branch (
5. Create a Pull Request.
For more details, check our contributing guidelines.
This project is licensed under the MIT License.
Thank you for using react-mailto!