@postbote/adapter-sendgrid
v1.0.0
Published
Postbote-Adapter für SendGrid (natives SDK)
Downloads
252
Readme
@postbote/adapter-sendgrid
Postbote adapter for SendGrid — native @sendgrid/mail SDK.
Installation
pnpm add @postbote/adapter-sendgridUsage
import { sendgrid } from "@postbote/adapter-sendgrid";
import { createPostbote } from "@postbote/core";
const postbote = createPostbote({
adapter: sendgrid({ apiKey: "SG...." }),
});
const result = await postbote.send({
from: "Acme <[email protected]>",
to: "[email protected]",
subject: "Welcome",
text: "Hello!",
});Options
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | — | SendGrid API key |
| client | MailService | — | Existing @sendgrid/mail instance (injectable) |
Client Injection
Pass a pre-configured SDK instance for testing or custom setup:
import sgMail from "@sendgrid/mail";
import { sendgrid } from "@postbote/adapter-sendgrid";
sgMail.setApiKey("SG....");
const adapter = sendgrid({ client: sgMail });Mapping
See @postbote/adapter-sendgrid-http — payload structure is similar (SDK handles personalizations).
Error Mapping
| Condition | Code |
|---|---|
| HTTP 401 / 403 | AUTH |
| HTTP 400 (body errors[].field) | INVALID_MESSAGE |
| HTTP 413 | INVALID_MESSAGE |
| HTTP 429 | RATE_LIMITED |
| HTTP 5xx / SDK error | PROVIDER_UNAVAILABLE |
| Timeout | TIMEOUT |
SendGrid has no synchronous recipient-rejected error — contract test skips
recipientRejected.
Message ID
Read from the X-Message-Id response header returned by the SDK.
HTTP variant
For a fetch-based, zero-dependency version (edge-compatible), see @postbote/adapter-sendgrid-http.
License
MIT — see LICENSE.md.
