@sendmux/sending
v1.6.0
Published
[](https://www.npmjs.com/package/@sendmux/sending) [](https://github.com/Sendmux/sendmux-sdk/actions/workflows/c
Readme
@sendmux/sending
Generated TypeScript client for the Sendmux Sending API.
Documentation
- Sending API reference: sendmux.ai/docs/sending-api/introduction
- Source repository: Sendmux/sendmux-sdk
Requirements
- A send-capable
smx_mbx_*key or owner-approved Sending-resourcesmx_agent_*token; alternatively, a REST OAuth grant for this surface. - A JavaScript runtime with the standard Fetch API.
Installation
npm install @sendmux/sendingOAuth access tokens
Pass accessToken instead of apiKey for a REST OAuth token or synchronous/asynchronous provider.
import { createSendingClient } from "@sendmux/sending";
const client = createSendingClient({
accessToken: () => process.env.SENDMUX_ACCESS_TOKEN!,
});The provider runs before each request. Your application owns token storage and refresh; required scopes still apply. See OAuth setup.
Usage
import {
createSendingClient,
sendingSendEmail,
} from "@sendmux/sending";
const client = createSendingClient({
apiKey: process.env.SENDMUX_SENDING_API_KEY!,
});
const response = await sendingSendEmail({
client,
body: {
from: { email: "[email protected]" },
to: { email: "[email protected]" },
subject: "Hello from Sendmux",
html_body: "<p>Hello.</p>",
text_body: "Hello.",
},
});
console.log(response.data?.data.message_id);The package exports every generated Sending operation plus:
createSendingClientconfigureSendingSendingClient- Node-only helpers from
@sendmux/sending/node:uploadAttachmentFromFile,sendEmailWithFiles, and explicit legacyattachmentFromFile
Attachments
For real files, upload bytes first and send with returned attachment_id refs. sendEmailWithFiles does that automatically, so file bytes never enter model context or the JSON send body. Inline base64 remains available only when you intentionally call attachmentFromFile for tiny generated content.
import { createSendingClient } from "@sendmux/sending";
import { sendEmailWithFiles } from "@sendmux/sending/node";
const client = createSendingClient({ apiKey: process.env.SENDMUX_SENDING_API_KEY! });
await sendEmailWithFiles({
client,
files: ["./report.pdf"],
headers: { "Idempotency-Key": "report-123" },
body: {
from: { email: "[email protected]" },
to: { email: "[email protected]" },
subject: "Report",
html_body: "<p>Attached.</p>",
},
});To upload first and compose the send yourself:
import { createSendingClient, sendingSendEmail } from "@sendmux/sending";
import { uploadAttachmentFromFile } from "@sendmux/sending/node";
const client = createSendingClient({ apiKey: process.env.SENDMUX_SENDING_API_KEY! });
const attachment = await uploadAttachmentFromFile({ client, filePath: "./report.pdf" });
await sendingSendEmail({
client,
body: {
from: { email: "[email protected]" },
to: { email: "[email protected]" },
subject: "Report",
html_body: "<p>Attached.</p>",
attachments: [{ attachment_id: attachment.data.attachment_id }],
},
});Request helpers
Use @sendmux/core when you need idempotency, conditional request, pagination, retry, or typed-error helpers.
import { idempotencyHeaders } from "@sendmux/core";
import { createSendingClient, sendingSendEmail } from "@sendmux/sending";
const client = createSendingClient({
apiKey: process.env.SENDMUX_SENDING_API_KEY!,
});
await sendingSendEmail({
client,
body: {
from: { email: "[email protected]" },
to: { email: "[email protected]" },
subject: "Receipt",
html_body: "<p>Thanks.</p>",
text_body: "Thanks.",
},
headers: idempotencyHeaders("email_123"),
});Support
Open an issue in Sendmux/sendmux-sdk with the package name, version, and request ID from any API error.
Licence
MIT. See the licence file.
