# MailerSend Integration via LowCodeAPI

## Overview

MailerSend is a transactional email service for sending emails, managing domains, templates, and monitoring email activity with powerful analytics.

## Base Endpoint

```
https://api.lowcodeapi.com/mailersend/
```

## Authentication

LowCodeAPI handles authentication automatically. You only need to:

1. **Sign up** at https://www.mailersend.com
2. **Connect your account** in LowCodeAPI dashboard
3. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your MailerSend API key from database
- Apply it to each request with proper Bearer token header

**Auth Type**: `API Key` (Bearer Token)

## API Categories

- Transactional Email
- Emails
- Domains
- Templates
- Webhooks
- Activity
- Suppressions
- Tokens
- Recipients

## Common Endpoints

### Category: Emails

#### Send an email

**Method**: `POST` | **LowCodeAPI Path**: `/v1/email`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/email?api_token={api_token}
```

**Description**: Send an asynchronous transactional email with rich formatting options.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Request Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `from` | object | No | Sender email and name |
| `to` | array | Yes | Array of recipient objects (email, name) |
| `cc` | array | No | Array of CC recipients |
| `bcc` | array | No | Array of BCC recipients |
| `reply_to` | object | No | Reply-to email and name |
| `subject` | string | No | Email subject (not required if template has default) |
| `text` | string | No | Plain text content |
| `html` | string | No | HTML content |
| `template_id` | string | No | Template ID to use |
| `attachments` | array | No | File attachments (base64 encoded) |
| `tags` | array | No | Tags for categorization (max 5) |
| `personalization` | array | No | Personalization data with {{var}} syntax |
| `send_at` | number | No | Unix timestamp to schedule sending |
| `settings` | object | No | Email tracking settings |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/email?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Sender Name"
    },
    "to": [
      {
        "email": "[email protected]",
        "name": "Recipient Name"
      }
    ],
    "subject": "Hello from MailerSend",
    "html": "<h1>Welcome!</h1><p>This is a test email.</p>",
    "text": "Welcome! This is a test email.",
    "tags": ["welcome", "onboarding"]
  }'
```

**Official Documentation**: https://developers.mailersend.com/api/v1/email.html#send-an-email

---

#### Send bulk emails

**Method**: `POST` | **LowCodeAPI Path**: `/v1/bulk-email`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/bulk-email?api_token={api_token}
```

**Description**: Send bulk emails to multiple recipients efficiently.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Request Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `from` | object | Yes | Sender email and name |
| `to` | array | Yes | Array of recipient objects |
| `subject` | string | Yes | Email subject |
| `text` | string | No | Plain text content |
| `html` | string | No | HTML content |
| `template_id` | string | No | Template ID to use |
| `tags` | array | No | Tags for categorization |
| `personalization` | array | No | Personalization data per recipient |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/bulk-email?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Newsletter"
    },
    "to": [
      {"email": "[email protected]", "name": "User One"},
      {"email": "[email protected]", "name": "User Two"}
    ],
    "subject": "Weekly Digest",
    "html": "<p>Your weekly update...</p>"
  }'
```

**Official Documentation**: https://developers.mailersend.com/api/v1/email.html#send-bulk-emails

---

### Category: Domains

#### List domains

**Method**: `GET` | **LowCodeAPI Path**: `/v1/domains`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/domains?page={page}&limit={limit}&api_token={api_token}
```

**Description**: Get a list of all verified domains in your account.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page` | number | No | Page number for pagination |
| `limit` | number | No | Number of results per page |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/domains?page=1&limit=50&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: https://developers.mailersend.com/api/v1/domains.html#get-a-list-of-domains

---

#### Get a domain

**Method**: `GET` | **LowCodeAPI Path**: `/v1/domains/domain_id`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/domains/domain_id?domain_id={domain_id}&api_token={api_token}
```

**Description**: Get detailed information about a specific domain.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `domain_id` | string | Yes | Domain ID from domain list |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
# domain_id from list domains response
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/domains/domain_id?domain_id=DOMAIN_ID&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: https://developers.mailersend.com/api/v1/domains.html#get-a-single-domain

---

#### Create a domain

**Method**: `POST` | **LowCodeAPI Path**: `/v1/domains`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/domains?api_token={api_token}
```

**Description**: Add a new domain to your account for sending emails.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Request Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `name` | string | Yes | Domain name to add |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/domains?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "mail.example.com"
  }'
```

**Official Documentation**: https://developers.mailersend.com/api/v1/domains.html#create-a-domain

---

### Category: Templates

#### List templates

**Method**: `GET` | **LowCodeAPI Path**: `/v1/templates`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/templates?page={page}&limit={limit}&api_token={api_token}
```

**Description**: Get a list of all email templates.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page` | number | No | Page number |
| `limit` | number | No | Results per page |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/templates?page=1&limit=20&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: https://developers.mailersend.com/api/v1/templates.html#get-a-list-of-templates

---

#### Create a template

**Method**: `POST` | **LowCodeAPI Path**: `/v1/templates`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/templates?api_token={api_token}
```

**Description**: Create a new email template with HTML and text content.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Request Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `name` | string | Yes | Template name |
| `html` | string | No | HTML content |
| `text` | string | No | Plain text content |
| `subject` | string | No | Default subject line |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/templates?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Template",
    "subject": "Welcome to Our Service",
    "html": "<h1>Welcome {{name}}!</h1><p>Thanks for joining.</p>",
    "text": "Welcome {{name}}! Thanks for joining."
  }'
```

**Official Documentation**: https://developers.mailersend.com/api/v1/templates.html#create-a-template

---

### Category: Activity

#### List activity events

**Method**: `GET` | **LowCodeAPI Path**: `/v1/activity`

**Full URL**:
```
https://api.lowcodeapi.com/mailersend/v1/activity?domain_id={domain_id}&event={event}&page={page}&limit={limit}&api_token={api_token}
```

**Description**: Get a list of activity events (opens, clicks, deliveries, etc.).

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `domain_id` | string | No | Filter by domain ID |
| `event` | string | No | Filter by event type |
| `date_from` | number | No | Unix timestamp - start date |
| `date_to` | number | No | Unix timestamp - end date |
| `page` | number | No | Page number |
| `limit` | number | No | Results per page |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
# Get recent email activity
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/activity?page=1&limit=100&api_token=YOUR_API_TOKEN"

# Filter by specific event
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/activity?event=activity.sent&page=1&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: https://developers.mailersend.com/api/v1/activity.html#get-a-list-of-events

---

## Usage Examples

### Example 1: Send HTML and Text Email

Send a rich email with both HTML and plain text versions.

```bash
# Send formatted email to single recipient
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/email?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]",
      "name": "Example Company"
    },
    "to": [
      {
        "email": "[email protected]",
        "name": "Customer Name"
      }
    ],
    "subject": "Your Order Has Shipped!",
    "html": "<h1>Order Shipped</h1><p>Your order #12345 has been shipped and will arrive in 2-3 business days.</p>",
    "text": "Order Shipped - Your order #12345 has been shipped.",
    "tags": ["order-update", "shipping"]
  }'
```

### Example 2: Send with Template

Use pre-configured templates for consistent messaging.

```bash
# Send email using stored template
# template_id from list templates
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/email?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from": {
      "email": "[email protected]"
    },
    "to": [
      {
        "email": "[email protected]"
      }
    ],
    "template_id": "TEMPLATE_ID",
    "personalization": [
      {
        "email": "[email protected]",
        "data": {
          "name": "John",
          "order_number": "12345"
        }
      }
    ]
  }'
```

### Example 3: Manage Domains and Templates

Configure your email infrastructure.

```bash
# List all verified domains
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/domains?api_token=YOUR_API_TOKEN"

# Get domain details
# domain_id from list response
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/domains/domain_id?domain_id=DOMAIN_ID&api_token=YOUR_API_TOKEN"

# List email templates
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/templates?api_token=YOUR_API_TOKEN"

# Create new template
curl -X POST "https://api.lowcodeapi.com/mailersend/v1/templates?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Password Reset",
    "subject": "Reset Your Password",
    "html": "<p>Click here to reset: {{reset_link}}</p>"
  }'
```

### Example 4: Monitor Email Activity

Track email performance and delivery status.

```bash
# Get recent activity events
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/activity?page=1&limit=50&api_token=YOUR_API_TOKEN"

# Get specific activity details
# event_id from activity list
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/activity/event_id?event_id=EVENT_ID&api_token=YOUR_API_TOKEN"

# Filter by event type
curl -X GET "https://api.lowcodeapi.com/mailersend/v1/activity?event=activity.opened&page=1&api_token=YOUR_API_TOKEN"
```

## Complete Endpoint Reference

For a complete list of all endpoints and their parameters, refer to:
- **OpenAPI Definition**: `https://backend.lowcodeapi.com/mailersend/definition`
- **Official Provider Documentation**: https://developers.mailersend.com

## Rate Limits & Best Practices

- Use bulk email API for sending to multiple recipients
- Templates ensure consistent branding and reduce payload size
- Monitor activity to track deliverability and engagement
- Set up proper DNS records for new domains before sending

## Error Handling

Standard HTTP status codes apply. Verify domain is verified and recipients are valid email addresses before sending.