Email sending — SMTP, API transports, attachments
Email builder and sender. SMTP transport, Resend API transport, attachment support, HTML + plain-text multipart, and a fluent interface.
composer require sugarcraft/sugar-post
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);
| Class | Method | Description |
|---|---|---|
| static new(from, to, ?subject, ?body) | Create an email | |
| withFrom() / withTo(...$to) / withCc(...) / withBcc(...) / withReplyTo() / withSubject() | Immutable header builders | |
| withBody() / withHtmlBody() / withSignature() | Plain-text and HTML bodies | |
| withAttachment(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 |
| Attachment | static fromPath(path, filename) / static inline(path, cid, filename) | Attachment value objects |
VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.