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

# Quickstart Guide

> Start sending emails in 5 minutes

## Installation

Install the Sendly SDK using npm, yarn, or pnpm:

<CodeGroup>
  ```bash npm theme={null}
  npm install @sendlyapp/sdk
  ```

  ```bash yarn theme={null}
  yarn add @sendlyapp/sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @sendlyapp/sdk
  ```
</CodeGroup>

## Basic setup

### 1. Get your API key

1. Go to [app.usesendly.com](https://app.usesendly.com)
2. Sign in to your account
3. Open **Settings** → **API Keys**
4. Copy your API key

### 2. Initialize the client

```javascript theme={null}
import { Sendly } from '@sendlyapp/sdk'

// Option 1: Pass the API key directly
const client = new Sendly('se_your_api_key')

// Option 2: Use an environment variable
// Set SENDLY_API_KEY in your .env file
const client = new Sendly()
```

## Your first email

```javascript theme={null}
const response = await client.emails.send({
  from: 'noreply@yourdomain.com',
  to: 'user@example.com',
  subject: 'Hello!',
  text: 'This is your first email with Sendly',
  html: '<h1>Hello!</h1><p>This is your first email with Sendly</p>'
})

console.log('Email sent:', response.id)
```

## Key concepts

### Sending domains

Before sending email, you need to verify a domain:

```javascript theme={null}
// Create a domain
const domain = await client.domains.create({
  domain: 'mail.yourdomain.com'
})

// Verify the domain (follow the DNS instructions)
await client.domains.verify(domain.id)

// Use the domain for sending
await client.emails.send({
  from: 'noreply@mail.yourdomain.com',
  to: 'user@example.com',
  subject: 'Email from your domain',
  html: '<p>Content here</p>'
})
```

### Delivery tracking

You can track the status of your emails:

```javascript theme={null}
// Send with tracking
const response = await client.emails.send({
  from: 'noreply@yourdomain.com',
  to: 'user@example.com',
  subject: 'Tracked email',
  html: '<p>Content</p>',
  tracking: {
    open: true,
    click: true
  }
})

// Check the status
const email = await client.emails.get(response.id)
console.log(`Status: ${email.status}`) // DELIVERED, BOUNCED, FAILED, etc.
```

## Error handling

Always wrap your calls in try/catch:

```javascript theme={null}
try {
  await client.emails.send({
    from: 'noreply@yourdomain.com',
    to: 'user@example.com',
    subject: 'Email',
    html: '<p>Content</p>'
  })
} catch (error) {
  if (error instanceof SendlyError) {
    console.error(`Error ${error.status}: ${error.message}`)
  } else {
    console.error('Unexpected error:', error)
  }
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Send emails" icon="envelope" href="/api/emails/send">
    Learn all sending options.
  </Card>

  <Card title="Webhooks" icon="webhook" href="/api/webhooks/list">
    Receive event notifications.
  </Card>

  <Card title="Best practices" icon="lightbulb" href="/best-practices">
    Improve your delivery rate.
  </Card>

  <Card title="Full reference" icon="book" href="/api-overview">
    Explore the complete API.
  </Card>
</CardGroup>
