Skip to content

gamboajorge49/Resend4Delphi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resend4D

Resend4D is a Delphi library for the Resend email API. It ships as a runtime package (Resend4Delphi.dpk) with no external dependencies beyond the Delphi RTL and RESTComponents.

Installation

Install via BOSS:

boss install github.com/gamboajorge49/Resend4D.git

Or add the src/ directory to your project's search path manually.

Quickstart

uses
  Resend4D, Resend4D.Types;

var
  Client: TResendClient;
  Message: TEmailMessage;
  Response: TEmailResponse;
begin
  Client := TResendClient.Create('re_xxxxxxxxx');
  Message := TEmailMessage.Create;
  try
    Message.From    := 'Acme <onboarding@resend.dev>';
    Message.&To     := ['user@example.com'];
    Message.Subject := 'Hello World';
    Message.HtmlBody := '<strong>Hello!</strong>';

    Response := Client.EmailSend(Message);
    try
      WriteLn('Sent! ID: ', Response.Id);
    finally
      Response.Free;
    end;
  finally
    Message.Free;
    Client.Free;
  end;
end;

Dependency injection (testing)

Pass a custom IResendHttpClient to replace the real HTTP layer:

Client := TResendClient.Create('re_test', MyMockHttpClient);

Available Operations

Emails — Sending

Method HTTP
EmailSend(msg) POST /emails
BatchEmailSend(msgs) POST /emails/batch
EmailRetrieve(id) GET /emails/{id}
EmailList(limit?, after?, before?) GET /emails
EmailUpdate(id, scheduledAt) PATCH /emails/{id}
EmailCancel(id) POST /emails/{id}/cancel
AttachmentRetrieve(emailId, attachmentId) GET /emails/{id}/attachments/{id}
AttachmentList(emailId) GET /emails/{id}/attachments

Emails — Receiving

Method HTTP
ReceivedEmailRetrieve(id, htmlFormat?) GET /emails/receiving/{id}
ReceivedEmailList(limit?, after?, before?) GET /emails/receiving
ReceivedAttachmentRetrieve(emailId, attachmentId) GET /emails/receiving/{id}/attachments/{id}
ReceivedAttachmentList(emailId) GET /emails/receiving/{id}/attachments

Broadcasts

Method HTTP
BroadcastCreate(msg) POST /broadcasts
BroadcastRetrieve(id) GET /broadcasts/{id}
BroadcastList(limit?, after?, before?) GET /broadcasts
BroadcastUpdate(id, msg) PATCH /broadcasts/{id}
BroadcastSend(id, scheduledAt?) POST /broadcasts/{id}/send
BroadcastDelete(id) DELETE /broadcasts/{id}

Logs

Method HTTP
LogRetrieve(id) GET /logs/{id}
LogList(limit?, after?, before?) GET /logs

API Keys

Method HTTP
ApiKeyCreate(name, permission?, domainId?) POST /api-keys
ApiKeyList(limit?, after?, before?) GET /api-keys
ApiKeyDelete(id) DELETE /api-keys/{id}

Contacts

Method HTTP
ContactCreate(msg) POST /contacts
ContactRetrieve(idOrEmail) GET /contacts/{idOrEmail}
ContactList(limit?, after?, before?) GET /contacts
ContactUpdate(idOrEmail, msg) PATCH /contacts/{idOrEmail}
ContactDelete(idOrEmail) DELETE /contacts/{idOrEmail}

Segments

Method HTTP
SegmentCreate(name) POST /segments
SegmentRetrieve(id) GET /segments/{id}
SegmentList(limit?, after?, before?) GET /segments
SegmentDelete(id) DELETE /segments/{id}
SegmentContactList(id, limit?, after?, before?) GET /segments/{id}/contacts

Templates

Method HTTP
TemplateCreate(msg) POST /templates
TemplateRetrieve(idOrAlias) GET /templates/{idOrAlias}
TemplateList(limit?, after?, before?) GET /templates
TemplateUpdate(idOrAlias, msg) PATCH /templates/{idOrAlias}
TemplateDelete(idOrAlias) DELETE /templates/{idOrAlias}
TemplateDuplicate(idOrAlias) POST /templates/{idOrAlias}/duplicate
TemplatePublish(idOrAlias) POST /templates/{idOrAlias}/publish

Webhooks

Method HTTP
WebhookCreate(msg) POST /webhooks
WebhookRetrieve(id) GET /webhooks/{id}
WebhookList(limit?, after?, before?) GET /webhooks
WebhookUpdate(id, msg) PATCH /webhooks/{id}
WebhookDelete(id) DELETE /webhooks/{id}

Automations

Method HTTP
AutomationCreate(msg) POST /automations
AutomationRetrieve(id) GET /automations/{id}
AutomationList(limit?, after?, before?) GET /automations
AutomationUpdate(id, msg) PATCH /automations/{id}
AutomationDelete(id) DELETE /automations/{id}
AutomationStop(id) POST /automations/{id}/stop
AutomationRunRetrieve(id, runId) GET /automations/{id}/runs/{runId}
AutomationRunList(id, limit?, after?, before?) GET /automations/{id}/runs

Events

Method HTTP
EventCreate(msg) POST /events
EventRetrieve(idOrName) GET /events/{idOrName}
EventList(limit?, after?, before?) GET /events
EventUpdate(idOrName, schemaJson) PATCH /events/{idOrName}
EventDelete(idOrName) DELETE /events/{idOrName}
EventSend(msg) POST /events/send

Topics

Method HTTP
TopicCreate(msg) POST /topics
TopicRetrieve(id) GET /topics/{id}
TopicList(limit?, after?, before?) GET /topics
TopicUpdate(id, msg) PATCH /topics/{id}
TopicDelete(id) DELETE /topics/{id}

Planned Operations

Group Operations
Domains Create, Retrieve, List, Update, Delete, Verify, Claim, Verify Claim, Get Claim
Audiences Create, Retrieve, List, Delete
Contacts Import, Get Import, List Imports, Get Topics, Update Topics, Add to Segment, List Segments, Delete from Segment
Contact Properties Create, Retrieve, List, Update, Delete

Ownership Rules

Callers are responsible for freeing all objects returned by TResendClient:

// Free single responses
Response := Client.EmailSend(Message);
try
  // use Response
finally
  Response.Free;
end;

// Free list responses — they own their items
List := Client.EmailList;
try
  for I := 0 to List.Data.Count - 1 do
    WriteLn(List.Data[I].Id);
finally
  List.Free; // frees items automatically
end;

Building

Open Resend4D.groupproj in RAD Studio. The project group contains:

  • src/Resend4Delphi.dproj — runtime package
  • test/Resend4DTests.dproj — DUnit test runner (Win32/Debug)
  • Demo/Demo.dproj — VCL demo application

There is no command-line build script; compilation is done inside the IDE.

Running Tests

Build and run test/Resend4DTests.dproj. A VCL window lists all test cases. Tests are fully offline — they use TMockResendHttpClient and never call the real Resend API.

Delphi Versions

Requires Delphi 10.3 Rio or later (uses System.Net.HttpClient and generics).

License

Resend4D is free and open-source software licensed under the MIT License.

About

Resend4D is a Delphi library for the [Resend](https://resend.com) email API

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages