Quick setup examples
Nuxt
Send your first email from a Nuxt server route using the mailblastr SDK.
Send your first email from a Nuxt app using the mailblastr Node SDK. Install it with npm install mailblastr, then import MailBlastr and call mb.emails.send(). A Nuxt server route keeps the key on the server, where it belongs.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
1. Install the SDK
npm install mailblastr2. Add your API key
Store your key in .env. Nuxt reads it server-side from process.env.
.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx3. Send email from a server route
Create a server route under server/api/send.ts. Instantiate the SDK client with the key from process.env and call mb.emails.send().
server/api/send.ts
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY);
export default defineEventHandler(async () => {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@example.com'],
subject: 'Hello world',
html: '<strong>It works!</strong>',
});
if (error) {
throw createError({ statusCode: 500, message: 'Error sending email' });
}
return data;
});A successful call returns the created email's
id. See the full request body in the Send an email reference.