Skip to main content

Installation & Setup

This guide covers everything you need to install and configure Inbound in your application, including SDK installation, environment configuration, and TypeScript setup.

SDK Installation

Install the Inbound SDK using your preferred package manager:
npm install inboundemail
The Inbound SDK is published as inboundemail on npm. It includes TypeScript definitions and works with Node.js 18+ and all modern JavaScript frameworks.
Current SDK Version: 0.18.0Check the changelog for the latest features and updates.

Getting Your API Key

1

Sign up for Inbound

Visit inbound.new and create an account. You can sign up with:
  • Email and password
  • GitHub OAuth
  • Google OAuth
2

Create an API key

Once logged in, navigate to Settings > API Keys and click Create API Key.Give your API key a descriptive name like “Production API” or “Development Environment”.
3

Copy and store securely

Copy your API key immediately - you won’t be able to see it again!
Never commit API keys to version control. Always use environment variables.

Environment Variables

Store your API key in environment variables for secure access:
Create a .env file in your project root:
.env
INBOUND_API_KEY=your_api_key_here
Add .env to your .gitignore:
.gitignore
.env
.env.local
.env.*.local

TypeScript Configuration

The Inbound SDK is written in TypeScript and includes full type definitions. No additional @types packages needed!
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "lib": ["ES2020"],
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}

Type Imports

The SDK exports comprehensive types for all API operations:
import { 
  Inbound,
  type InboundWebhookPayload,
  type InboundEmail,
  type InboundEmailAddress,
  type InboundAttachment,
  isInboundWebhookPayload 
} from 'inboundemail'
Use isInboundWebhookPayload() to validate webhook payloads with type narrowing in TypeScript.

Framework-Specific Setup

Next.js 15 App Router

Create a route handler for webhooks:
app/api/webhooks/email/route.ts
import { NextRequest, NextResponse } from 'next/server'
import { Inbound, isInboundWebhookPayload } from 'inboundemail'

const inbound = new Inbound(process.env.INBOUND_API_KEY!)

export async function POST(request: NextRequest) {
  const payload = await request.json()
  
  if (!isInboundWebhookPayload(payload)) {
    return NextResponse.json({ error: 'Invalid webhook' }, { status: 400 })
  }
  
  // Process email
  console.log('Email received:', payload.email.subject)
  
  return NextResponse.json({ success: true })
}

Next.js Pages Router

pages/api/webhooks/email.ts
import type { NextApiRequest, NextApiResponse } from 'next'
import { Inbound, isInboundWebhookPayload } from 'inboundemail'

const inbound = new Inbound(process.env.INBOUND_API_KEY!)

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' })
  }
  
  const payload = req.body
  
  if (!isInboundWebhookPayload(payload)) {
    return res.status(400).json({ error: 'Invalid webhook' })
  }
  
  // Process email
  console.log('Email received:', payload.email.subject)
  
  return res.status(200).json({ success: true })
}

Initializing the Client

Create an Inbound client instance to interact with the API:
import { Inbound } from 'inboundemail'

const inbound = new Inbound(process.env.INBOUND_API_KEY!)

Client Configuration Options

The Inbound client accepts optional configuration:
const inbound = new Inbound(process.env.INBOUND_API_KEY!, {
  baseUrl: 'https://api.inbound.new', // Custom API base URL
  timeout: 30000, // Request timeout in milliseconds (default: 30000)
})
Most users don’t need to configure these options. The defaults work for all production use cases.

Verification

Verify your installation is working:
verify.ts
import { Inbound } from 'inboundemail'

const inbound = new Inbound(process.env.INBOUND_API_KEY!)

async function verify() {
  try {
    // List domains to verify API connection
    const domains = await inbound.domains.list()
    console.log('✅ Inbound SDK connected successfully!')
    console.log(`You have ${domains.data.length} domain(s) configured`)
  } catch (error) {
    console.error('❌ Failed to connect:', error)
  }
}

verify()
Run the verification script:
node verify.ts

Troubleshooting

If you see Cannot find module 'inboundemail':
  1. Verify the package is installed: npm list inboundemail
  2. Delete node_modules and reinstall: rm -rf node_modules && npm install
  3. Clear your build cache: rm -rf .next (Next.js) or equivalent
If TypeScript can’t find the types:
  1. Ensure you’re using TypeScript 5.0+
  2. Check your tsconfig.json includes "moduleResolution": "bundler" or "node"
  3. Try restarting your TypeScript server in your editor
If you get 401 Unauthorized errors:
  1. Verify your API key is correct
  2. Check the environment variable is loaded: console.log(process.env.INBOUND_API_KEY)
  3. Ensure you’re not accidentally committing your .env file
  4. Regenerate your API key if you suspect it’s compromised
If your webhook endpoint isn’t receiving emails:
  1. Verify your webhook URL is publicly accessible
  2. Check your email address configuration: inbound.emailAddresses.list()
  3. Ensure your endpoint returns a 200 status code
  4. Test locally with bun run inbound-webhook-test hello@yourdomain.com
  5. Check your domain’s DNS records are properly configured

Next Steps

Quickstart Guide

Follow the quickstart to send your first email and receive webhooks

API Reference

Explore all available SDK methods and API endpoints

Webhook Examples

See real-world examples of webhook processing

Webhook Verification

Learn how to verify webhooks and test locally

Build docs developers (and LLMs) love