
Overview
QStash is a serverless message queue by Upstash. It lets you publish HTTP requests that get delivered reliably with automatic retries, delays, scheduling, and dead-letter queues. Because QStash can publish to any HTTP endpoint, it works with AutoSend out of the box. You do not need a dedicated integration. QStash forwards your request (including theAuthorization header) directly to the AutoSend API.
This is useful when you want to:
- Send emails reliably without blocking your main request
- Retry failed email sends automatically
- Schedule emails for a future time (e.g., 24 hours after signup)
- Queue high-volume sends without overwhelming your app
Prerequisites
Before you start, make sure you have:- An AutoSend account with an API key - get one at autosend.com
- An Upstash account with a QStash token - get one at upstash.com
- Node.js 18+ (or any environment that supports
fetch)
How It Works
QStash acts as a proxy between your app and the AutoSend API. Instead of callinghttps://api.autosend.com/v1/mails/send directly, you publish the request to QStash. QStash then delivers it to AutoSend, handling retries and scheduling for you.
Your App → QStash → AutoSend API → Email delivered
Your Authorization: Bearer <AUTOSEND_API_KEY> header is forwarded to AutoSend using QStash’s header-forwarding mechanism (Upstash-Forward-*).
Installation
Install the QStash JavaScript SDK:Quickstart
Set Environment Variables
Add these to your
.env file:.env
Get your AutoSend API key from the API Keys page in your dashboard, and your QStash token from the Upstash console.
Send a Single Email
Use
client.publishJSON with the AutoSend mail send endpoint as the URL. Pass your AutoSend API key in the Upstash-Forward-Authorization header. QStash strips the Upstash-Forward- prefix before forwarding the request, so AutoSend receives a standard Authorization: Bearer ... header.publishJSON automatically sets Content-Type: application/json and serializes the body.Response from QStash:This is the QStash message ID, not the AutoSend email ID. The email is queued and will be delivered asynchronously.
Send a Bulk Email
For bulk sends, use the bulk send endpoint and provide a
recipients array instead of a single to field.Send Using a Template
If you have a template configured in AutoSend, pass
templateId and dynamicData instead of html. Learn more about email templates and template variables.Scheduling and Retries
Schedule a Delayed Email
Use thedelay option to send an email at a future time. This is useful for follow-up sequences, onboarding drips, or reminders.
notBefore:
Configure Retries
By default, QStash retries failed requests 3 times. You can configure this:- 2xx response - Email successfully queued by AutoSend. No retry needed.
- Non-2xx response - QStash retries automatically based on your retry configuration.
to, from), and missing content (html, text, or templateId).
Advanced Features
Using Queues
If you want concurrency control, for example limiting how many emails are sent per second, use a QStash queue withenqueueJSON.
parallelism on the queue in your Upstash console.
Using a Callback URL
If you want to know when QStash has successfully delivered the email request to AutoSend, you can pass acallback URL. QStash will POST the response from AutoSend to this URL after delivery.
Using Deduplication
If your app might accidentally publish the same email twice (e.g., due to a retry on your side), use adeduplicationId to prevent duplicates.
deduplicationId was already published in the last 24 hours, QStash will reject the duplicate silently.
Complete Examples
Post-Signup Email Flow (Next.js)
Post-Signup Email Flow (Next.js)
A full example of a Next.js API route that queues a welcome email when a user signs up.
Onboarding Drip Sequence
Onboarding Drip Sequence
Queue multiple emails at different delays when a user signs up.
Header Reference
| Header | Description |
|---|---|
Upstash-Forward-Authorization | Forwards Authorization: Bearer <token> to AutoSend. Required for authentication. |
Upstash-Forward-Content-Type | Forwards Content-Type to AutoSend. The SDK sets this automatically when using publishJSON. |
Upstash-Forward- is stripped of the prefix and forwarded to the destination URL. This is how QStash passes your AutoSend API key without exposing it as a QStash-level credential.
When to Use This Integration
Use QStash with AutoSend when you need:- Scheduled email delivery - send emails at a specific time without a cron job
- Retry handling without custom logic - QStash retries failed requests automatically
- Async processing for heavy workloads - offload email sending from your main request
- Decoupled architecture - separate email delivery from your application logic
Best Practices
Keep requests fast
Keep requests fast
publishJSON returns a messageId as soon as QStash accepts your message. AutoSend is called asynchronously after that. Avoid doing heavy processing before publishing to QStash.Use deduplication for idempotency
Use deduplication for idempotency
QStash may retry requests on transient failures. To avoid sending duplicate emails, always include a unique
deduplicationId tied to the email intent (e.g., welcome-${userId}). See the deduplication section for details.Secure your API key
Secure your API key
Always send your AutoSend API key via the
Upstash-Forward-Authorization header. Never expose it in client-side code or include it in request bodies.Avoid large payloads
Avoid large payloads
Keep request payloads lightweight. Store large files externally and reference them when possible. Attachments must stay within AutoSend’s size limits.
Use templates for scale
Use templates for scale
Prefer
templateId with dynamicData instead of large inline HTML payloads. Templates are more performant, easier to maintain, and can be updated without code changes. Learn more about email templates.What QStash Does Not Handle
QStash handles reliable delivery to the AutoSend API. The following are handled by AutoSend, not QStash:- Whether the email was actually delivered to the recipient’s inbox
- Bounce and complaint handling
- Unsubscribe tracking
- Open and click tracking
Troubleshooting
Email not delivered
Email not delivered
Check the QStash dashboard in your Upstash console. You can see message status, retry attempts, and the response body from AutoSend. If the message is in the Dead Letter Queue (DLQ), the AutoSend API returned a persistent error.Solution: Review the message details in the Upstash console and check your Email Activity dashboard for delivery status.
401 Unauthorized from AutoSend
401 Unauthorized from AutoSend
Messages delivering to wrong endpoint
Messages delivering to wrong endpoint
Double-check your
url is https://api.autosend.com/v1/mails/send for single sends or https://api.autosend.com/v1/mails/bulk for bulk sends.Solution: Refer to the API Reference for the correct endpoint URLs.Duplicate emails
Duplicate emails
Use a
deduplicationId that is unique per email intent (e.g., welcome-${userId}). See the deduplication section above.Solution: Add a unique deduplicationId to every publishJSON call where duplicate sends are possible.Next Steps
Email Templates
Create reusable, personalized email templates for transactional emails.
Webhooks
Use webhooks to notify your application about email and contact events in real-time.
Sending Domain
Verify and authenticate your domain on AutoSend for sending emails.
Email Activity
Track delivery, performance, and troubleshoot issues for your transactional emails.