npm package: @flightdev/email
Description: Email adapters for Flight Framework - Resend, SendGrid, SMTP
Latest version: 0.0.7

# @flightdev/email

Email sending for Flight Framework. Unified API for multiple email providers.

## Table of Contents

- [Installation](#installation)
- [Quick Start](#quick-start)
- [Adapters](#adapters)
- [Sending Emails](#sending-emails)
- [Templates](#templates)
- [API Reference](#api-reference)
- [License](#license)

---

## Installation

```bash
npm install @flightdev/email
```

---

## Quick Start

```typescript
import { createEmail } from '@flightdev/email';
import { resend } from '@flightdev/email/resend';

const email = createEmail(resend({
    apiKey: process.env.RESEND_API_KEY,
}));

await email.send({
    from: 'hello@example.com',
    to: 'user@example.com',
    subject: 'Welcome!',
    html: '<h1>Welcome to our platform!</h1>',
});
```

---

## Adapters

### Resend

Modern email API with React support.

```typescript
import { resend } from '@flightdev/email/resend';

const adapter = resend({
    apiKey: process.env.RESEND_API_KEY,
});
```

### Postmark

Transactional email service.

```typescript
import { postmark } from '@flightdev/email/postmark';

const adapter = postmark({
    serverToken: process.env.POSTMARK_SERVER_TOKEN,
});
```

### SendGrid

Scalable email delivery.

```typescript
import { sendgrid } from '@flightdev/email/sendgrid';

const adapter = sendgrid({
    apiKey: process.env.SENDGRID_API_KEY,
});
```

### AWS SES

Amazon Simple Email Service.

```typescript
import { ses } from '@flightdev/email/ses';

const adapter = ses({
    region: 'us-east-1',
    credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    },
});
```

### SMTP

Any SMTP server.

```typescript
import { smtp } from '@flightdev/email/smtp';

const adapter = smtp({
    host: 'smtp.example.com',
    port: 587,
    secure: false,
    auth: {
        user: 'username',
        pass: 'password',
    },
});
```

---

## Sending Emails

### Basic Email

```typescript
await email.send({
    from: 'noreply@example.com',
    to: 'user@example.com',
    subject: 'Hello',
    text: 'Plain text content',
    html: '<p>HTML content</p>',
});
```

### Multiple Recipients

```typescript
await email.send({
    from: 'noreply@example.com',
    to: ['user1@example.com', 'user2@example.com'],
    cc: ['manager@example.com'],
    bcc: ['archive@example.com'],
    subject: 'Team Update',
    html: '<p>...</p>',
});
```

### Attachments

```typescript
await email.send({
    from: 'noreply@example.com',
    to: 'user@example.com',
    subject: 'Your Invoice',
    html: '<p>Please find your invoice attached.</p>',
    attachments: [
        {
            filename: 'invoice.pdf',
            content: pdfBuffer,
            contentType: 'application/pdf',
        },
    ],
});
```

---

## Templates

### React Email (with Resend)

```tsx
import { render } from '@react-email/render';
import { WelcomeEmail } from './emails/welcome';

const html = render(<WelcomeEmail username="John" />);

await email.send({
    from: 'hello@example.com',
    to: 'user@example.com',
    subject: 'Welcome!',
    html,
});
```

---

## API Reference

### email.send(options)

| Option | Type | Description |
|--------|------|-------------|
| `from` | `string` | Sender email address |
| `to` | `string \| string[]` | Recipient(s) |
| `subject` | `string` | Email subject |
| `html` | `string` | HTML body |
| `text` | `string` | Plain text body |
| `cc` | `string[]` | CC recipients |
| `bcc` | `string[]` | BCC recipients |
| `replyTo` | `string` | Reply-to address |
| `attachments` | `Attachment[]` | File attachments |

### Attachment

| Property | Type | Description |
|----------|------|-------------|
| `filename` | `string` | File name |
| `content` | `Buffer \| string` | File content |
| `contentType` | `string` | MIME type |

---

## License

MIT