--- name: send-bulk-sms title: "Send Bulk SMS" description: "Send SMS messages to multiple recipients." language: python framework: flask telnyx_products: [SMS/MMS] channel: [sms] --- # Production-ready Flask application for sending bulk SMS via Telnyx. Production-ready Flask application for sending bulk SMS via Telnyx. ## Telnyx API Endpoints Used - **Send Message**: `POST /v2/messages` — [API reference](https://developers.telnyx.com/api/messaging/send-message) ## Architecture ``` API Request │ ▼ ┌──────────────────┐ │ Telnyx Messaging │ └────────┬─────────┘ │ └──► JSON response ``` ## Environment Variables Copy `.env.example` to `.env` and fill in: | Variable | Type | Example | Required | Description | Where to get it | |----------|------|---------|----------|-------------|-----------------| | `TELNYX_API_KEY` | `string` | `KEY0123456789ABCDEF` | **yes** | Telnyx API v2 key | [Portal](https://portal.telnyx.com/api-keys) | | `TELNYX_PHONE_NUMBER` | `string` | `your_value` | **yes** | Telnyx phone number | — | | `BULK_SMS_RATE_LIMIT` | `string` | `10` | no | Bulk sms rate limit | — | | `BULK_SMS_DELAY` | `string` | `0.1` | no | Bulk sms delay | — | | `FLASK_DEBUG` | `string` | `false` | no | Flask debug | — | ## Setup ```bash git clone https://github.com/team-telnyx/telnyx-code-examples.git cd telnyx-code-examples/send-bulk-sms-python cp .env.example .env # ← fill in your credentials pip install -r requirements.txt python app.py # starts on http://localhost:5000 ``` ### Webhook Configuration 1. Expose your local server: ```bash ngrok http 5000 ``` 2. Copy the HTTPS URL and configure in [Telnyx Portal](https://portal.telnyx.com): - **Messaging Profile** → Inbound Webhook URL → `https://.ngrok.io/webhooks/sms` ## API Reference ### `POST /sms/bulk/send` HTTP endpoint to send bulk SMS messages. ```bash curl -X POST http://localhost:5000/sms/bulk/send \ -H "Content-Type: application/json" \ -d '{ "to": "+12125551234", "message": "Hello from Telnyx!" }' ``` **Response:** ```json { "message_id": "msg-f5d7a7e0-1234-5678", "status": "queued", "to": "+12125551234", "segments": 1 } ``` ### `GET /sms/bulk/status` Health check endpoint for bulk SMS service. ```bash curl http://localhost:5000/sms/bulk/status ``` **Response:** ```json { "messages": [ { "id": "msg-f5d7a7e0-1234-5678", "to": "+12125551234", "text": "Your appointment is confirmed for July 18 at 2:30 PM", "status": "delivered", "sent_at": "2026-07-15T14:30:00Z" } ] } ``` ## Troubleshooting - **Connection refused on port 5000**: App isn't running. Run `python app.py` and check no other process uses port 5000. - **401 Unauthorized**: Your `TELNYX_API_KEY` is invalid. Generate a new one at [portal.telnyx.com/api-keys](https://portal.telnyx.com/api-keys). ## Related Examples - [Abandoned Cart Recovery (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/abandoned-cart-recovery-python/README.md) - [Accounting Tax Season Line (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/accounting-tax-season-line-python/README.md) - [After Hours Nurse Triage (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/after-hours-nurse-triage-python/README.md) - [AI Appointment Booking SMS Flow (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-appointment-booking-sms-flow-python/README.md) - [AI Appointment Reminder SMS Voice (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-appointment-reminder-sms-voice-python/README.md) ## Resources - [Messaging Guide](https://developers.telnyx.com/docs/messaging) - [Telnyx Developer Docs](https://developers.telnyx.com) - [Telnyx Portal](https://portal.telnyx.com) ## Why Telnyx Telnyx is an **AI Communications Infrastructure** platform — voice, messaging, SIP, AI, and IoT on one private, global network.