Send email with Nuxt
A Nitro server route, with the key in runtimeConfig.
You need a verified sending domain and an API key from Settings › API Keys. If neither exists yet, the quickstart covers both in a couple of minutes.
Install
npm i sending-sdkSend
import { Sending } from "sending-sdk";
export default defineEventHandler(async (event) => {
const { sendingApiKey } = useRuntimeConfig();
const { email, userId } = await readBody(event);
const sending = new Sending({ apiKey: sendingApiKey });
return sending.emails.send({
from: "Acme <[email protected]>",
to: email,
subject: "Welcome",
html: "<p>You're in.</p>",
idempotencyKey: `welcome-${userId}`,
});
});A successful call answers 202 with the message id: accepted and queued, not yet delivered. Delivery, opens, bounces and complaints arrive later, on webhooks or in the dashboard.
What changes in Nuxt
Anything under runtimeConfig without the public prefix stays on the server. The env var that fills it is NUXT_SENDING_API_KEY.
The thing that catches people
Put the key in runtimeConfig.public and it ships to the browser in the payload. That is a full-account credential in your page source.
Next
- All the fields: cc and bcc, reply-to, attachments, templates, scheduling.
- Webhooks: delivery, bounce and complaint events, signed with HMAC.
- Domains: SPF, DKIM and MAIL FROM, and why sending is refused until they are in place.
- MCP: the same operations as tools, when the one writing the code is an agent.