mailpush
v0.1.1
Published
Official Mailpush SDK for JavaScript/TypeScript
Maintainers
Readme
Mailpush
Official JavaScript/TypeScript SDK for Mailpush.
Installation
npm install mailpush
# or
bun add mailpush
# or
yarn add mailpushQuick Start
import { Mailpush } from "mailpush";
const mailpush = new Mailpush("mp_live_xxx");
await mailpush.emails.send({
from: "[email protected]",
to: "[email protected]",
subject: "Hello from Mailpush",
html: "<h1>Welcome!</h1><p>Your account is ready.</p>",
});Usage
Send an email
const { id, messageId } = await mailpush.emails.send({
from: "[email protected]",
to: "[email protected]",
subject: "Welcome!",
html: "<h1>Hello</h1>",
text: "Hello",
});Send to multiple recipients
await mailpush.emails.send({
from: "[email protected]",
to: ["[email protected]", "[email protected]"],
cc: "[email protected]",
bcc: ["[email protected]", "[email protected]"],
subject: "Team Update",
html: "<p>Important update for the team.</p>",
});Send with a template
await mailpush.emails.send({
from: "[email protected]",
to: "[email protected]",
templateId: "your-template-id",
variables: {
name: "John",
company: "Acme Inc",
},
});Send with attachments
import { readFileSync } from "fs";
await mailpush.emails.send({
from: "[email protected]",
to: "[email protected]",
subject: "Your invoice",
html: "<p>Please find your invoice attached.</p>",
attachments: [
{
filename: "invoice.pdf",
content: readFileSync("invoice.pdf").toString("base64"),
contentType: "application/pdf",
},
],
});Configuration
const mailpush = new Mailpush("mp_live_xxx", {
baseUrl: "https://api.mailpush.app", // default
});Error Handling
import {
Mailpush,
MailpushError,
AuthenticationError,
ValidationError,
RateLimitError,
} from "mailpush";
try {
await mailpush.emails.send({ ... });
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Invalid API key");
} else if (error instanceof ValidationError) {
console.error("Invalid request:", error.details);
} else if (error instanceof RateLimitError) {
console.error(`Rate limited. Retry after ${error.retryAfter}s`);
} else if (error instanceof MailpushError) {
console.error(`Error: ${error.message} (${error.code})`);
}
}License
MIT
