Dart SDK
Official Dart / Flutter client for the Mailofly REST API. Package:mailofly · Requires: Dart 3.0+ · Quickstart: Dart
Install
Initialize
Send email
With a saved template
client.compose.send is deprecated and forwards to /v1/emails.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
mailofly · Requires: Dart 3.0+ · Quickstart: Dart
dependencies:
mailofly: ^0.1.1
dart pub add mailofly
# or
flutter pub add mailofly
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();
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();
}
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.
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>',
},
]);
| 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') |
// 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',
});
final meta = await Mailofly.discovery();
print(meta['resources']);