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

# Dart

# Dart SDK

Official **Dart / Flutter** client for the Mailofly REST API.

**Package:** [`mailofly`](https://pub.dev/packages/mailofly) · **Requires:** Dart 3.0+ · **Quickstart:** [Dart](../getting-started/dart.md)

***

## Install

```yaml theme={null}
dependencies:
  mailofly: ^0.1.1
```

```bash theme={null}
dart pub add mailofly
# or
flutter pub add mailofly
```

***

## Initialize

```dart theme={null}
import 'package:mailofly/mailofly.dart';

final client = Mailofly(
  apiKey: 'mf_live_…',
  // baseUrl: 'https://www.mailofly.com', // optional
);

// Always close when done (releases the HTTP client)
await client.close();
```

Create an API key under **[API keys](https://www.mailofly.com/user/api-keys)** first.

***

## Send email

```dart theme={null}
try {
  final result = await client.emails.send(
    from: 'Acme <onboarding@example.com>',
    to: ['alex@example.com'],
    subject: 'Hello',
    html: '<p>Thanks for signing up.</p>',
    tags: [{'name': 'category', 'value': 'welcome'}],
  );
  print('Sent: ${result['id']}');
} on MailoflyException catch (e) {
  print('${e.statusCode} ${e.error} ${e.message}');
} finally {
  client.close();
}
```

### With a saved template

```dart theme={null}
await client.emails.send(
  from: 'Acme <onboarding@example.com>',
  to: ['alex@example.com'],
  template: {
    'id': 'uuid-of-template',
    'variables': {'first_name': 'Alex'},
  },
);
```

`client.compose.send` is deprecated and forwards to `/v1/emails`.

### Batch send (up to 100 emails)

```dart theme={null}
final result = await client.batch.send([
  {
    'from': 'Acme <onboarding@example.com>',
    'to': ['foo@example.com'],
    'subject': 'hello world',
    'html': '<h1>it works!</h1>',
  },
  {
    'from': 'Acme <onboarding@example.com>',
    'to': ['bar@example.com'],
    'subject': 'world hello',
    'html': '<p>it works!</p>',
  },
]);
```

***

## Resources

| API       | Dart methods                                                                    |
| --------- | ------------------------------------------------------------------------------- |
| Accounts  | `client.accounts.list()`, `create`, `get`, `update`, `delete`                   |
| Contacts  | `client.contacts.list(segmentId: …)`, `create`, `get`, `update`, `delete`       |
| Templates | `client.templates.list()`, …                                                    |
| Segments  | `client.segments.list()`, … plus `client.segments.contacts(id).list/add/remove` |
| Campaigns | `client.campaigns.list()`, …, `runs`, `send`                                    |
| Emails    | `client.emails.list()`, `get`, `send`, `sendRaw`                                |
| Batch     | `client.batch.send([…])`                                                        |
| Compose   | `client.compose.send(…)` (deprecated)                                           |
| Mail logs | `client.mailLogs.list(page: 1, pageSize: 20, status: 'sent')`                   |

### Examples

```dart theme={null}
// List sending accounts
final accounts = await client.accounts.list();
print(accounts['data']);

// Create a contact
await client.contacts.create({
  'email': 'alex@example.com',
  'first_name': 'Alex',
});
```

***

## Discovery (no API key)

```dart theme={null}
final meta = await Mailofly.discovery();
print(meta['resources']);
```

***

## Related

* [Dart quickstart](../getting-started/dart.md)
* [API: Emails](https://docs.mailofly.com/api/emails)


## Related topics

- [SDKs](/sdks/index.md)
- [Dart](/getting-started/dart.md)
- [Http](/getting-started/http.md)
- [Manage Emails](/sending/manage-emails.md)
- [Introduction](/sending/introduction.md)
