← All 19 apps

SugarPost

SugarPost

Email sending — SMTP, API transports, attachments

port of charmbracelet/skate emailmailsmtpattachment

SugarPost code coverage

Email builder and sender. SMTP transport, Resend API transport, attachment support, HTML + plain-text multipart, and a fluent interface.

Install

composer require sugarcraft/sugar-post

Quickstart

use SugarCraft\Post\{Email, ResendTransport, SmtpTransport};

// Immutable: every with*() returns a new Email
$email = Email::new('noreply@example.com', 'user@example.com', 'Deployment complete', 'Your app was deployed successfully.')
    ->withHtmlBody('<p>Your app was deployed <strong>successfully</strong>.</p>')
    ->withCc('ops@example.com')
    ->withAttachment('build.zip', '/tmp/build.zip');   // display name, then the file on disk

$transport = new SmtpTransport('smtp.example.com', 587, 'user', 'secret');
$transport->send($email);

// Or over the Resend HTTP API (key from the argument or RESEND_API_KEY)
(new ResendTransport())->send($email);

What's in the box

SMTP transportTCP connection with TLS, auth (plain/login), and batching.
Resend transportAPI-based sending via Resend.com — no SMTP needed.
AttachmentsLocal files, memory content, custom MIME types.
HTML + TextMultipart/alternative email bodies.

Source & demos

Try the quickstart →

API

ClassMethodDescription
Emailstatic new(from, to, ?subject, ?body)Create an email
EmailwithFrom() / withTo(...$to) / withCc(...) / withBcc(...) / withReplyTo() / withSubject()Immutable header builders
EmailwithBody() / withHtmlBody() / withSignature()Plain-text and HTML bodies
EmailwithAttachment(filename, path) / withInlineAttachment(path, cid, filename)Attach a file, or embed one for a cid: reference
SmtpTransport__construct(host, port = 587, username = '', password = '', timeout = 30, heloHost = '') / send(Email)SMTP delivery
ResendTransport__construct(apiKey = '') / send(Email)Resend API delivery; falls back to RESEND_API_KEY
Attachmentstatic fromPath(path, filename) / static inline(path, cid, filename)Attachment value objects

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Email DTOs + transports

Email DTOs + transports

Plain + multipart Email values, transport surface listed.