frontmail 0.1.0
frontmail: ^0.1.0 copied to clipboard
Send emails from Flutter and Dart apps through your Frontmail templates with the public key – retries with idempotency, delivery status and Cloudflare Turnstile helpers.
// Sends one email from the command line:
// dart run example/main.dart pk_… tpl_… you@example.com
// In a Flutter app the calls are the same – see the README for a form with Turnstile.
import 'package:frontmail/frontmail.dart';
Future<void> main(List<String> args) async {
if (args.length < 3) {
print('usage: dart run example/main.dart <public key> <template id> <email>');
return;
}
final frontmail = Frontmail(publicKey: args[0]);
try {
final result = await frontmail.send(
templateId: args[1],
params: {'email': args[2], 'message': 'Hello from Dart!'},
);
print(result.status == DeliveryStatus.held
? 'Received – it will be delivered shortly.'
: 'Sent ${result.messageId}');
final status = await frontmail.status(messageId: result.messageId, statusToken: result.statusToken);
print('Status: ${status.status} (${status.events.map((e) => e.type).join(', ')})');
} on FrontmailException catch (e) {
print('${e.code}: ${e.message} – ${e.docsUrl}');
} finally {
frontmail.close();
}
}