Attachments
Attach files and inline images to a message as bytes.
An attachment is a Uint8Array with a file name and a content type. The package copies the bytes and never reads file paths or fetches URLs, so load the file yourself.
Example (Attaching a Text File)
import { } from "effect";
import { } from "@effect-kit/emails";
const = .(function* () {
const = yield* ;
return yield* .({
: "billing@example.com",
: "ada@example.com",
: "Invoice 1042",
: "Your invoice is attached.",
: [
{
: "invoice-1042.txt",
: new ().("Total: 42.00"),
: "text/plain",
},
],
});
});| Field | Rules |
|---|---|
filename | Not blank, no control characters |
content | Uint8Array |
contentType | Must look like type/subtype |
contentId | Optional. No whitespace or angle brackets. Unique within the message |
Inline images
An attachment with a contentId is inline. Reference it from the HTML with a cid: URL.
Example (Embedding a Logo in the HTML Body)
import { } from "effect";
import { } from "@effect-kit/emails";
declare const : ;
const = .(function* () {
const = yield* ;
return yield* .({
: "hello@example.com",
: "ada@example.com",
: "Welcome",
: '<img src="cid:logo@example.com" alt="Example" />',
: [
{
: "logo.png",
: ,
: "image/png",
: "logo@example.com",
},
],
});
});Provider support
Attachments and inline images are capabilities, and a message that needs one the provider lacks fails with UnsupportedFeatureError before any request.
- No attachments: MailerSend, Brevo and Plunk.
- No inline images: Mailgun, MailerSend, Brevo, Scaleway, Mailchimp Transactional and Plunk.
Lettermint content ids
Lettermint rejects an inline contentId that does not contain @, with InvalidMessageError.
Use a qualified id such as logo@example.com.