Prerequisites
Use a verified sending domain, your account ID, and a domain-scoped send-only API v2 key. Use sandbox mode for every test. Management tasks need a separate full API key. Use Node.js 22 and Azure Functions Core Tools v4. The code uses the Node.js v4 programming model.Install the Dependencies
Run these commands in a new directory:Try a Sandbox Send
Run this short SDK check locally before adding the longer server integration below. Use a verified sender, a send-only API key, and your account ID. It sends to a reserved test address withsandbox: true, so no email is delivered.
In the server project directory, add .env to .gitignore, then create .env with AHASEND_API_KEY, AHASEND_ACCOUNT_ID, and AHASEND_FROM (an address on your verified domain). Keep these values out of browser code and AI prompts. Use Node.js 22 or newer. Save this as quick-send.mjs:
quick-send.mjs
node --env-file=.env quick-send.mjs from that directory. The output lists each recipient status; queued or scheduled means accepted for sandbox processing. The process exits with a failure if the request or any recipient fails. Continue below for the full integration.
Add the Shared Sending Code
Save this assend-email.cjs beside the function file. Configure AHASEND_API_KEY, AHASEND_ACCOUNT_ID, AHASEND_FROM, AHASEND_TO and a long random SEND_TOKEN on the server. Set AHASEND_TO=recipient@example.com and AHASEND_DELIVERY_MODE=sandbox for local testing. Keep a sandbox credential until you are ready for real delivery; changing the mode to live alone cannot override a sandbox credential.
send-email.cjs
Create the HTTP Function
Save this asindex.cjs. The function accepts POST requests and also checks your server’s bearer token; Azure’s function key is an additional hosted check.
index.cjs
host.json:
host.json
Run with Core Tools
Keep.env and local.settings.json out of Git. Export the variables from the shared code, then start the local host:
SEND_TOKEN set, invoke the local function:
Prepare the Hosted App
Select Node.js 22 and Functions runtime v4. Put the values in app settings, with Key Vault references for secrets. Send the Azure function key asx-functions-key in addition to the bearer token. Use your application’s identity checks and request limits before allowing callers to trigger mail. Follow Microsoft’s deployment steps to publish the app.
Track final delivery with webhooks. Also see Azure in Python, Azure in Go and Node.js SMTP.
Related Guides
- Before sending: verify a domain and create a send-only key.
- Other ways to send: REST API, SMTP, CLI quickstart, Node.js SDK and Go SDK.
- Request rules: API authentication, scopes, idempotency, errors and rate limits.
- Testing and events: sandbox mode, CLI webhook testing, event payloads, signature verification and delivery retries.
- Data and limits: retention, tracking and plans and feature availability.

