Tutorial1 min read

Mail sender API — send email programmatically with a REST API

A practical mail sender API guide for developers. Learn how an api email sender works, payload shapes, authentication, and production patterns with Piisend.

Mail sender API — send email programmatically with a REST API

A mail sender API lets your backend send email without running your own SMTP server. An api email sender handles authentication, queueing, delivery, bounces, and compliance — you focus on business logic.

Anatomy of a mail sender API

Typical flow:

  1. Your server calls POST /emails with recipient, subject, and body (HTML and/or text)
  2. The provider validates the request and enqueues the message
  3. You receive a message ID synchronously
  4. Delivery events arrive via webhooks or appear in logs

Piisend follows this model. See the full reference at /docs/api.

Minimal send request

const res = await fetch('https://api.piisend.com/v1/emails', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PIISEND_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    to: 'user@example.com',
    subject: 'Password reset',
    html: '<p>Click <a href="https://app.example.com/reset">here</a> to reset.</p>',
    text: 'Reset your password: https://app.example.com/reset',
  }),
});

Always include a plain-text part for accessibility and deliverability.

Production patterns for api email sender integrations

Idempotent retries

Network failures happen. Use idempotency keys when retrying POST requests so users do not receive duplicate OTP emails. Details in sending docs.

Template-based sends

For repeated layouts, store HTML in Piisend templates and pass merge variables at send time — templates guide.

Webhook verification

Treat webhook payloads as untrusted until you verify signatures. Configure endpoints in the dashboard and handle bounce events to maintain list hygiene.

Next steps

Start sending

Ship transactional email in minutes

Create an API key, verify a domain, and send your first message with Piisend.