mailofly 0.1.1
mailofly: ^0.1.1 copied to clipboard
Official Dart client for the Mailofly REST API (one-off compose, contacts, templates, campaigns, and more).
mailofly #
Official Dart client for the Mailofly REST API.
Requirements #
- Dart 3.0 or newer (Flutter compatible).
Install #
dependencies:
mailofly: ^0.1.1
dart pub add mailofly
Usage #
Create a client with your API key from User → API keys:
import 'package:mailofly/mailofly.dart';
Future<void> main() async {
final client = Mailofly(apiKey: 'mf_live_…');
try {
final accounts = await client.accounts.list();
print(accounts['data']);
await client.compose.send(
accountKey: 'acc_…',
subject: 'Hi {{first_name}}',
body: '<p>Thanks for signing up.</p>',
to: 'you@example.com',
// or: toList: ['a@b.com', 'c@d.com'],
// or: contactIds: ['uuid-…'],
cc: ['cc@example.com'],
bcc: ['bcc@example.com'],
variables: {'first_name': 'Alex'},
);
} on MailoflyException catch (e) {
print('${e.statusCode} ${e.error} ${e.message}');
} finally {
client.close();
}
}
Discovery (no API key) #
final meta = await Mailofly.discovery();
print(meta['resources']);
Resources #
| API | Dart |
|---|---|
| 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 |
| Compose | client.compose.send(accountKey: …, subject: …, body: …, to: …) or sendRaw |
| Mail logs | client.mailLogs.list(page: 1, pageSize: 20, status: 'sent') |
Request/response JSON matches /api/v1.
Custom base URL & HTTP client #
final client = Mailofly(
apiKey: 'mf_live_…',
baseUrl: 'https://www.mailofly.com',
httpClient: myClient, // optional; default closes when you call client.close()
);
License #
MIT