> For the complete documentation index, see [llms.txt](https://support.mailagent.email/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.mailagent.email/widget/installation.md).

# Installation

## Script Tag (Recommended)

The simplest way to add MailAgent to your website is with a single `<script>` tag. Place it before the closing `</body>` tag:

```html
<script
  src="https://widget.mailagent.email/connect/connect.js"
  data-user-id="YOUR_USER_ID"
></script>
```

This registers the global `window.MailAgent` object. You can then open the widget from anywhere in your code.

### With Configuration

Pass configuration directly via `data-*` attributes on the script tag:

```html
<script
  src="https://widget.mailagent.email/connect/connect.js"
  data-user-id="YOUR_USER_ID"
  data-suggestions='[
    {"icon": "✉️", "text": "Write a professional email"},
    {"icon": "📝", "text": "Summarize this thread"}
  ]'
  data-header-transparent="true"
  data-color-background-primary="#2c7df6"
></script>
```

## Single Page Applications (React, Vue, Next.js, etc.)

For SPAs, add the script tag to your root HTML file (`index.html`, `_document.tsx`, etc.) or load it dynamically:

```javascript
// Load the connect script dynamically
const script = document.createElement('script');
script.src = 'https://widget.mailagent.email/connect/connect.js';
script.dataset.userId = 'YOUR_USER_ID';
document.body.appendChild(script);
```

### React Example

```tsx
import { useEffect, useRef } from 'react';

function ChatWidget() {
  const widgetRef = useRef(null);

  const openChat = async () => {
    if (widgetRef.current?.mounted) return;

    widgetRef.current = await MailAgent.open({
      bottom: '20px',
      right: '20px',
      width: '400px',
      height: '600px',
    });
  };

  return <button onClick={openChat}>Open Chat</button>;
}
```

### Next.js Example

Add the script in `app/layout.tsx` or `pages/_document.tsx`:

```tsx
import Script from 'next/script';

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Script
          src="https://widget.mailagent.email/connect/connect.js"
          data-user-id="YOUR_USER_ID"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}
```

## Verify Installation

Open your browser's developer console and type:

```javascript
typeof window.MailAgent // should return "object"
```

If it returns `"object"`, the widget is loaded and ready to use.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://support.mailagent.email/widget/installation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
