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.
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:
- Your server calls
POST /emailswith recipient, subject, and body (HTML and/or text) - The provider validates the request and enqueues the message
- You receive a message ID synchronously
- 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
- Email for developers — conceptual overview
- Quickstart — API key and first send in five minutes