dart_resend 2.0.0 copy "dart_resend: ^2.0.0" to clipboard
dart_resend: ^2.0.0 copied to clipboard

A production-ready Dart SDK for the complete Resend email API.

dart_resend

GitHub repository Pub package version Test status 100% line coverage

Pub points Pub likes Monthly Pub downloads Dart SDK constraint License

GitHub stars GitHub forks Open GitHub issues Open GitHub pull requests GitHub contributors GitHub last commit GitHub repository size

A production-ready, community-maintained Dart SDK for the complete Resend API.

The public surface tracks the official Resend API reference and its canonical OpenAPI specification.

dart_resend 2.0 provides typed request and response models, cursor pagination, request metadata, predictable exceptions, local validation, dependency-injected HTTP transport, and first-class support for every current Resend resource.

Developed with 💙 and maintained by coderave

Important notes #

  • Keep API keys on a trusted server. Never embed a Resend API key in a web, Flutter, mobile, desktop, or other distributed client. Route those requests through your own authenticated backend.
  • 2.0.0 is an intentional breaking redesign. The singleton, ResendClient, ResendResult, legacy feature clients, and legacy response classes were removed. See the migration guide.
  • Audiences were removed. Resend's current API uses global Contacts and Segments. The package no longer exposes the retired Audiences resource.
  • Suppressions are private beta. The API is implemented, but calls only work for Resend teams with access to the gated feature.

Install #

dart pub add dart_resend

The package requires Dart 3.8 or newer.

Quick start #

import 'package:dart_resend/dart_resend.dart';

Future<void> sendEmail(String apiKey) async {
  final Resend resend = Resend(apiKey: apiKey);
  try {
    final ResendResponse<ResendId> response = await resend.emails.send(
      SendEmailRequest.raw(
        from: 'Acme <onboarding@resend.dev>',
        to: <String>['delivered@resend.dev'],
        subject: 'Hello from dart_resend',
        html: '<strong>It works!</strong>',
        text: 'It works!',
      ),
    );
    print(response.data.id);
  } finally {
    resend.close();
  }
}

Run the complete quick start with an environment variable:

RESEND_API_KEY=re_... dart run example/main.dart

See the runnable example.

Client lifecycle #

Create one Resend instance per application or service and reuse it. Calling close() releases the internally owned HTTP client and is safe to do more than once. Calls made after closing fail with StateError.

When an http.Client is injected, it remains caller-owned by default. Set closeClient: true if Resend.close() should close the injected client too. The constructor also accepts a request timeout, defaultHeaders, and custom baseUri for tests or compatible gateways. See useConfiguredClient.

OAuth registration and token endpoints do not require an API key. Use Resend.unauthenticated() for those calls and an authenticated Resend client for team resources and OAuth grant management.

Responses, pagination, and errors #

Every network method returns Future<ResendResponse<T>>. The response contains the decoded data, HTTP statusCode, immutable lowercase headers, Resend requestId, and parsed rateLimit metadata. Response models also retain their complete immutable payload in json, so newly added server fields remain available before the SDK adds typed getters.

List operations accept PaginationOptions(limit:, after:, before:) and return ResendPage<T>, whose data and hasMore fields drive cursor iteration. after and before are mutually exclusive; limits must be between 1 and 100. See cursor iteration and response metadata.

Failures are thrown as typed exceptions:

  • ResendApiException for non-2xx API responses, including the status, error name, request ID, headers, parsed details, and raw body.
  • ResendTimeoutException when the configured timeout expires.
  • ResendNetworkException for other transport failures.
  • ResendDecodeException when a successful response cannot be decoded.
  • ArgumentError, RangeError, or StateError for invalid local usage.

See the complete error-handling example.

Complete feature and example index #

Every public Resend operation is demonstrated below. The linked files are part of the analyzed package examples and use only the public library entrypoint.

Emails #

Batch sends support tags but not attachments or scheduled_at. A batch may contain 1–100 emails and can use strict all-or-nothing or permissive per-item validation.

Domains #

Domain DNS models preserve unknown record kinds and types for forward compatibility. A configured tracking subdomain can currently be replaced and reverified, but not removed.

API keys #

The token returned by apiKeys.create is shown only once; store it in a secret manager and never log it.

Broadcasts #

Templates #

Contacts and imports #

Contacts are global. Use segments for grouping and topics for granular contact preferences; use unsubscribed for the global broadcast preference.

Segments #

Topics #

Contact properties #

Webhooks #

Never parse and re-encode a webhook body before verification. Verification uses the raw request body and throws ResendWebhookVerificationException for an invalid signature, timestamp, or payload.

API logs #

Automations and runs #

Automation graph builders validate the trigger, unique keys, endpoints, reachability, connection branches, and duplicate connections before sending.

Custom events #

Suppressions (private beta) #

These calls require private-beta access on the authenticated Resend team:

OAuth 2.1 and PKCE #

Use a cryptographically random state, bind it to the browser session, and store the PKCE verifier securely until the callback. OAuth access and refresh tokens are secrets and must remain server-side. Authorization URLs default to https://api.resend.com/oauth/authorize; override authorizationBaseUri only for an intentional compatible service or test environment.

Version 2 migration #

Version 2 deliberately does not include compatibility shims for the old API. Read MIGRATION.md for old-to-new call mappings, the new exception model, and the Audiences-to-Segments migration.

Contributing #

See CONTRIBUTING.md for package development, tests, coverage, documentation, and pull-request requirements.

2
likes
160
points
457
downloads

Documentation

API reference

Publisher

verified publishercoderave.dev

Weekly Downloads

A production-ready Dart SDK for the complete Resend email API.

Repository (GitHub)
View/report issues
Contributing

Topics

#email #resend #api #sdk

License

GPL-3.0 (license)

Dependencies

crypto, http

More

Packages that depend on dart_resend