> ## Documentation Index
> Fetch the complete documentation index at: https://checkly-422f444a-immanuel-fix-api-spec.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# EmailAlertChannel Construct

> Learn how to configure email alert channels with the Checkly CLI.

<Tip>
  Learn more about Email alerts in [the email alert documentation](/integrations/alerts/email).
</Tip>

Use Email Alert Channels to send email notifications when checks fail or recover.

<CodeGroup>
  ```ts Basic Example theme={null}
  import { EmailAlertChannel } from "checkly/constructs"

  const emailChannel = new EmailAlertChannel("email-channel-1", {
    address: "alerts@acme.com",
  })
  ```

  ```ts Advanced Example theme={null}
  import { EmailAlertChannel } from "checkly/constructs"

  const emailChannel = new EmailAlertChannel("ops-email-channel", {
    address: "ops-team@acme.com",
    sendRecovery: true,
    sendFailure: true,
    sendDegraded: true,
    sslExpiry: true,
    sslExpiryThreshold: 30,
  })
  ```
</CodeGroup>

## Configuration

<Tabs>
  <Tab title="Email Alert Channel">
    Configure Email-specific settings:

    | Parameter | Type     | Required | Default | Description                            |
    | --------- | -------- | -------- | ------- | -------------------------------------- |
    | `address` | `string` | ✅        | -       | Email address to send notifications to |
  </Tab>

  <Tab title="General Alert Channel">
    Configure common alert channel properties:

    | Property             | Type      | Required | Default | Description                                              |
    | -------------------- | --------- | -------- | ------- | -------------------------------------------------------- |
    | `sendRecovery`       | `boolean` | ❌        | `true`  | Send notifications when checks recover                   |
    | `sendFailure`        | `boolean` | ❌        | `true`  | Send notifications when checks fail                      |
    | `sendDegrade`        | `boolean` | ❌        | `false` | Send notifications when checks degrade (API checks only) |
    | `sslExpiry`          | `boolean` | ❌        | `false` | Send notifications for SSL certificate expiry            |
    | `sslExpiryThreshold` | `number`  | ❌        | `30`    | Days before SSL expiry to send notification              |
  </Tab>
</Tabs>

### Email Alert Channel Options

<ResponseField name="address" type="string" required>
  Email address to send notifications to. Each EmailAlertChannel supports only one email address.

  **Usage:**

  ```ts highlight={2} theme={null}
  new EmailAlertChannel('team-email', {
    address: 'dev-team@acme.com'
  })
  ```

  **Examples:**

  <CodeGroup>
    ```ts Team Notifications theme={null}
    const teamEmail = new EmailAlertChannel("team-email", {
      address: "dev-team@acme.com",
    })

    new ApiCheck("api-health-check", {
      name: "API Health Check",
      alertChannels: [teamEmail],
      request: {
        method: "GET",
        url: "https://api.acme.com/health",
      },
    })
    ```

    ```ts Individual Developer theme={null}
    const developerEmail = new EmailAlertChannel("developer-email", {
      address: "john.doe@acme.com",
    })

    new ApiCheck("personal-project-check", {
      name: "Personal Project Check",
      alertChannels: [developerEmail],
      request: {
        method: "GET",
        url: "https://johnspersonalapi.com/status",
      },
    })
    ```
  </CodeGroup>

  **Use cases**: Team notifications, individual alerts, distribution lists, role-based alerting.
</ResponseField>

### General Alert Channel Options

<ResponseField name="sendRecovery" type="boolean">
  Whether to send notifications when checks recover from failure or degraded state.

  **Usage:**

  ```ts highlight={3} theme={null}
  new EmailAlertChannel("recovery-email", {
    address: "ops@acme.com",
    sendRecovery: true, // Send recovery notifications
  })
  ```

  **Examples:**

  <CodeGroup>
    ```ts Recovery Notifications theme={null}
    const opsEmail = new EmailAlertChannel("ops-email", {
      address: "ops@acme.com",
      sendRecovery: true, // Get notified when issues are resolved
      sendFailure: true,
    })
    ```

    ```ts Failure Only theme={null}
    const alertsEmail = new EmailAlertChannel("alerts-only", {
      address: "alerts@acme.com",
      sendRecovery: false, // Only failures, no recovery notifications
      sendFailure: true,
    })
    ```
  </CodeGroup>

  **Use cases**: Recovery confirmation, operational awareness, noise reduction.
</ResponseField>

<ResponseField name="sendFailure" type="boolean">
  Whether to send notifications when checks fail.

  **Usage:**

  ```ts highlight={3} theme={null}
  new EmailAlertChannel("failure-email", {
    address: "oncall@acme.com",
    sendFailure: true, // Send failure notifications
  })
  ```

  **Examples:**

  <CodeGroup>
    ```ts Failures Only theme={null}
    const criticalEmail = new EmailAlertChannel("critical-email", {
      address: "oncall@acme.com",
      sendFailure: true,
      sendRecovery: false,
      sendDegraded: false,
    })
    ```

    ```ts All Notifications theme={null}
    const comprehensiveEmail = new EmailAlertChannel("all-notifications", {
      address: "monitoring@acme.com",
      sendFailure: true,
      sendRecovery: true,
      sendDegraded: true,
    })
    ```
  </CodeGroup>

  **Use cases**: Incident response, failure monitoring, operational alerting.
</ResponseField>

<ResponseField name="sendDegraded" type="boolean">
  Whether to send notifications when API checks degrade (performance thresholds exceeded but not failed).

  **Usage:**

  ```ts highlight={3} theme={null}
  new EmailAlertChannel("performance-email", {
    address: "performance-team@acme.com",
    sendDegraded: true, // Send degraded performance notifications
  })
  ```

  **Use cases**: Performance monitoring, early warning systems, SLA tracking.
</ResponseField>

<ResponseField name="sslExpiry" type="boolean">
  Whether to send notifications for SSL certificate expiry warnings.

  **Usage:**

  ```ts highlight={3} theme={null}
  new EmailAlertChannel("security-email", {
    address: "security@acme.com",
    sslExpiry: true,
    sslExpiryThreshold: 30, // Alert 30 days before expiry
  })
  ```

  **Use cases**: Certificate management, security compliance, proactive maintenance.
</ResponseField>

<ResponseField name="sslExpiryThreshold" type="number">
  Number of days before SSL certificate expiry to send notifications. Only relevant when `sslExpiry` is enabled.

  **Usage:**

  ```ts highlight={4} theme={null}
  new EmailAlertChannel("ssl-monitoring", {
    address: "devops@acme.com",
    sslExpiry: true,
    sslExpiryThreshold: 30, // Alert 30 days before expiry
  })
  ```

  **Use cases**: Certificate renewal planning, compliance management, operational scheduling.
</ResponseField>

## Examples

<CodeGroup>
  ```ts Multiple Recipients theme={null}
  // Create separate channels for different recipients
  const devEmail = new EmailAlertChannel("dev-email", {
    address: "dev@acme.com",
    sendDegraded: true,
  })

  const opsEmail = new EmailAlertChannel("ops-email", {
    address: "ops@acme.com",
    sendFailure: true,
    sendRecovery: true,
  })

  const managerEmail = new EmailAlertChannel("manager-email", {
    address: "manager@acme.com",
    sendFailure: true,
    sendRecovery: false,
  })

  new ApiCheck("important-service", {
    name: "Important Service Check",
    alertChannels: [devEmail, opsEmail, managerEmail],
    request: {
      method: "GET",
      url: "https://api.acme.com/important",
    },
  })
  ```

  ```ts Comprehensive Setup theme={null}
  // Full configuration example
  const comprehensiveEmail = new EmailAlertChannel("comprehensive-alerts", {
    address: "monitoring@acme.com",
    sendRecovery: true, // Know when issues are resolved
    sendFailure: true, // Critical for incident response
    sendDegraded: true, // Early warning for performance issues
    sslExpiry: true, // Certificate management
    sslExpiryThreshold: 30, // One month notice
  })

  new ApiCheck("comprehensive-monitoring", {
    name: "Comprehensive API Monitoring",
    maxResponseTime: 10000,
    degradedResponseTime: 5000,
    alertChannels: [comprehensiveEmail],
    request: {
      method: "GET",
      url: "https://api.acme.com/comprehensive",
    },
  })
  ```
</CodeGroup>

<Info>
  **Single Email Address**: EmailAlertChannel only accepts one email address. For multiple recipients, create separate EmailAlertChannel instances or use distribution lists.
</Info>

<Warning>
  **Email Delivery**: Email notifications may be subject to spam filters or delivery delays. For critical alerts, consider combining email with other notification methods like SMS or Slack.
</Warning>

## Reference an alert channel by ID

If your Checkly account includes alert channels that are not controlled via Checkly constructs, find the email channel ID in the Checkly web UI or via the API and set it using `EmailAlertChannel.fromId()`.

<Tabs>
  <Tab title="Web UI">
    1. Go to [Alert Channels](https://app.checklyhq.com/alerts/) in your Checkly dashboard
    2. Find your email channel and note the ID in the URL or channel details
  </Tab>

  <Tab title="API">
    ```bash theme={null}
    curl -H "Authorization: Bearer YOUR_API_KEY" \
         -H "X-Checkly-Account: YOUR_ACCOUNT_ID" \
         https://api.checklyhq.com/v1/alert-channels/
    ```
  </Tab>
</Tabs>

```ts Using Existing Channel theme={null}
// Reference an existing email channel by ID
const existingEmailChannel = EmailAlertChannel.fromId(123)

new ApiCheck("existing-channel-check", {
  name: "Check with Existing Channel",
  alertChannels: [existingEmailChannel],
  request: {
    method: "GET",
    url: "https://api.acme.com/endpoint",
  },
})
```
