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

# Send Email

> Trigger a new email to a customer

Trigger a new email to a customer using a template and recipient information.

<Note>
  This endpoint sends an email using a specified template with variable
  substitution. The email will be sent immediately or scheduled for later
  delivery.
</Note>

## Request

<ParamField body="template_id" type="string" required>
  The unique identifier of the email template to use
</ParamField>

<ParamField body="recipient_email" type="string" required>
  The email address of the recipient
</ParamField>

<ParamField body="recipient_name" type="string" required>
  The name of the recipient
</ParamField>

<ParamField body="callout_id" type="string" required>
  The unique identifier of the callout associated with this email
</ParamField>

<ParamField body="variables" type="object" required>
  Key-value pairs for template variable substitution
</ParamField>

<ParamField body="scheduled_time" type="string">
  ISO 8601 timestamp for when to send the email (optional, defaults to
  immediate)
</ParamField>

<ParamField body="priority" type="string">
  Priority level of the email (low, medium, high, urgent)
</ParamField>

<ParamField body="email_type" type="string">
  Type of email (payment\_reminder, follow\_up, welcome, notification, marketing)
</ParamField>

<ParamField body="metadata" type="object">
  Additional metadata for the email (campaign\_id, department, etc.)
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token for API authentication
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
       --url https://api.credira.com/v1/send-email \
       --header 'Authorization: Bearer YOUR_API_KEY' \
       --header 'Content-Type: application/json' \
       --data '{
         "template_id": "template_123456789",
         "recipient_email": "customer@example.com",
         "recipient_name": "John Doe",
         "callout_id": "callout_987654321",
         "variables": {
           "customer_name": "John Doe",
           "invoice_number": "INV-001",
           "amount": "1250.00",
           "due_date": "2024-01-30"
         },
         "scheduled_time": "2024-01-15T14:30:00Z",
         "priority": "high",
         "email_type": "payment_reminder",
         "metadata": {
           "campaign_id": "camp_123",
           "department": "billing",
           "invoice_amount": 1250.0
         }
       }'
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.credira.com/v1/send-email", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      template_id: "template_123456789",
      recipient_email: "customer@example.com",
      recipient_name: "John Doe",
      callout_id: "callout_987654321",
      variables: {
        customer_name: "John Doe",
        invoice_number: "INV-001",
        amount: "1250.00",
        due_date: "2024-01-30",
      },
      scheduled_time: "2024-01-15T14:30:00Z",
      priority: "high",
      email_type: "payment_reminder",
      metadata: {
        campaign_id: "camp_123",
        department: "billing",
        invoice_amount: 1250.0,
      },
    }),
  });

  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample status="200" summary="Success">
  ```json theme={null}
  {
    "success": true,
    "data": {
      "id": "email_123456789",
      "template_id": "template_123456789",
      "callout_id": "callout_987654321",
      "recipient_email": "customer@example.com",
      "recipient_name": "John Doe",
      "subject": "Payment Reminder - Invoice #INV-001",
      "status": "scheduled",
      "scheduled_time": "2024-01-15T14:30:00Z",
      "account_id": "acc_789123456",
      "created_time": "2024-01-15T10:30:00Z",
      "email_type": "payment_reminder",
      "priority": "high",
      "estimated_delivery": "2024-01-15T14:30:00Z",
      "tracking_id": "track_456789123",
      "metadata": {
        "campaign_id": "camp_123",
        "department": "billing",
        "invoice_amount": 1250.0
      }
    },
    "meta": {
      "timestamp": "2024-01-15T10:30:00Z",
      "request_id": "req_123456789",
      "message": "Email has been scheduled successfully"
    }
  }
  ```
</ResponseExample>

<ResponseExample status="400" summary="Bad Request">
  ```json theme={null}
  {
    "success": false,
    "error": {
      "code": "INVALID_REQUEST",
      "message": "Missing required field: template_id"
    },
    "meta": {
      "timestamp": "2024-01-15T10:30:00Z",
      "request_id": "req_123456789"
    }
  }
  ```
</ResponseExample>

<ResponseExample status="401" summary="Unauthorized">
  ```json theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Invalid or missing API key"
    },
    "meta": {
      "timestamp": "2024-01-15T10:30:00Z",
      "request_id": "req_123456789"
    }
  }
  ```
</ResponseExample>

<ResponseExample status="422" summary="Unprocessable Entity">
  ```json theme={null}
  {
    "success": false,
    "error": {
      "code": "VALIDATION_ERROR",
      "message": "Invalid email address format",
      "details": "Email address must be a valid format"
    },
    "meta": {
      "timestamp": "2024-01-15T10:30:00Z",
      "request_id": "req_123456789"
    }
  }
  ```
</ResponseExample>

<ResponseExample status="429" summary="Too Many Requests">
  ```json theme={null}
  {
    "success": false,
    "error": {
      "code": "RATE_LIMITED",
      "message": "Too many email requests. Please wait before sending another email."
    },
    "meta": {
      "timestamp": "2024-01-15T10:30:00Z",
      "request_id": "req_123456789"
    }
  }
  ```
</ResponseExample>
