> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paysight.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Tenant Email API

> This API allows you to send emails using your own authorized domains. A domain needs to be first added and verified in Paysight before it can be used.

## Authentication

Authentication is done using a `tenant_key` which is a UUID associated with your account. This key must be included in all API requests.

### Tenant Key

Your tenant key can be found under Settings in your Paysight account.

## Domain Authorization

You can only send emails from domains that have been authorized for your account. Domains can be managed within Paysight under Settings. (Coming soon). For now, please contact your account manager to add a domain to your account.

## Endpoints

### Send a Single Email

**Endpoint:** `POST https://app.paysight.io/api/email`

**Request Body:**

```json theme={null}
{
  "tenant_key": "uuid-of-tenant",
  "from": "sender@authorized-domain.com",
  "to": "recipient@example.com", // Can also be an array of email addresses
  "subject": "Email Subject",
  "replyTo": "reply@somedomain.com", // Optional - any email address (customer care address or otherwise)
  "cc": "cc@example.com", // Optional, can also be an array
  "bcc": "bcc@example.com", // Optional, can also be an array
  "templateType": "react", // "react" or "string"
  "templateName": "generic", // Required for "react" templateType
  "templateContent": "<html>...</html>", // Required for "string" templateType
  "data": {
    // Data to populate the template
    "heading": "Welcome",
    "bodyContent": "This is the email content",
    "ctaText": "Click Here",
    "ctaUrl": "https://example.com"
  },
  "idempotencyKey": "optional-custom-idempotency-key" // Optional
}
```

> **Note:** For security reasons, loading templates from files is not supported. Templates must be provided directly in the `templateContent` field when using the "string" templateType.

**Response:**

```json theme={null}
{
  "success": true,
  "message": "Email sent successfully",
  "data": {
    "message": "Email sent successfully",
    "id": "email-id",
    "to": "recipient@example.com",
    "tenantKey": "uuid-of-tenant"
  }
}
```

### Send Batch Emails

**Endpoint:** `POST https://app.paysight.io/api/email/batch`

**Request Body:**

```json theme={null}
{
  "tenant_key": "uuid-of-tenant",
  "emails": [
    {
      "from": "sender@authorized-domain.com",
      "to": "recipient1@example.com",
      "subject": "Email Subject 1",
      "templateType": "react",
      "templateName": "generic",
      "data": {
        "heading": "Welcome User 1",
        "bodyContent": "This is the email content for user 1"
      }
    },
    {
      "from": "sender@authorized-domain.com",
      "to": "recipient2@example.com",
      "subject": "Email Subject 2",
      "templateType": "string",
      "templateContent": "<html>Hello {{name}}</html>",
      "data": {
        "name": "User 2"
      }
    }
  ],
  "idempotencyKey": "optional-custom-idempotency-key" // Optional
}
```

**Response:**

```json theme={null}
{
  "success": true,
  "message": "Batch emails sent successfully",
  "data": {
    "message": "Batch emails sent successfully",
    "count": 2,
    "responses": [
      {
        "id": "email-id-1"
      },
      {
        "id": "email-id-2"
      }
    ],
    "tenantKey": "uuid-of-tenant"
  }
}
```

## Error Responses

### Invalid Request Format

```json theme={null}
{
  "success": false,
  "error": "Validation error",
  "details": {
    // Validation error details
  }
}
```

### Invalid Tenant Key

```json theme={null}
{
  "success": false,
  "error": "Invalid tenant key or tenant not found"
}
```

### Unauthorized Domain

```json theme={null}
{
  "success": false,
  "error": "Domain 'unauthorized-domain.com' is not authorized for this tenant"
}
```

### Server Error

```json theme={null}
{
  "success": false,
  "error": "Server error",
  "details": "Error message"
}
```

## Idempotency

The API supports idempotency to prevent duplicate emails from being sent. You can provide your own `idempotencyKey` in the request, or the API will generate one based on the content of the request.

Idempotency keys expire after 7 days.

## Templates

### React Templates

The following React templates are available:

* `generic`: A generic email template with heading, body content, and CTA button
* `order-confirmation`: An order confirmation email template
* `welcome-membership`: A welcome email for new members

### String Templates

String templates support variable substitution using the `{{variable}}` syntax and conditional blocks using `{{#if variable}}...{{/if}}`.

Example:

```html theme={null}
<div>
  <h1>Hello {{name}}!</h1>
  <p>{{message}}</p>
  {{#if showButton}}
  <a href="{{buttonUrl}}">{{buttonText}}</a>
  {{/if}}
</div>
```

## Implementation Notes

* Domain verification ensures you can only send from authorized domains
* Idempotency prevents duplicate emails from being sent
* All emails are tracked for monitoring and debugging purposes
