Developer Quick-Start: Learn how to send MMS multimedia messages using Node.js, Express, and MessageBird API. Step-by-step tutorial covering setup, file size limits, carrier specifications, error handling, and production deployment. Want to skip 10DLC vetting queues, carrier surcharges, and multi-step SDK boilerplate? You can send the same SMS directly via SMSRoute's REST API with instant no-KYC provisioning.
Build a production-ready Node.js MMS API using Express and MessageBird to send multimedia messages (images, GIFs, videos) programmatically. This tutorial covers MessageBird MMS integration with Node.js 22, Express.js, and the MessageBird Node.js SDK. You'll create a robust API endpoint that handles multimedia message delivery with proper file size validation, carrier-specific limits, error handling, and security best practices for production environments.
By the end, you'll have a functional MMS API endpoint (POST /send-mms) that accepts recipient
phone numbers, message text, and media URLs (images, GIFs, videos, PDFs) to dispatch multimedia messages
through MessageBird's infrastructure. This forms a foundational building block for Node.js applications
requiring rich media notifications, marketing campaigns, customer engagement, or multimedia communication
features. This assumes basic understanding of Node.js, npm (or yarn), and REST APIs.
Project Overview and Goals
- Goal: Build a Node.js Express server with a single API endpoint (POST /send-mms). The endpoint receives a recipient phone number, optional message body, and media URL, then uses the MessageBird Node.js SDK to send an MMS message to the recipient.
- Problem Solved: Send rich media content (images, GIFs, videos) alongside text messages programmatically from your applications using MessageBird's messaging infrastructure.
- Technologies:
- Node.js: JavaScript runtime environment for server-side applications.
- Express.js: Minimal, flexible Node.js web framework for creating API endpoints.
- Vite: Modern frontend build tool. As of 2025, Vite 7.1 is current, requiring Node.js 20.19+ or 22.12+. Vite 7 improved the Environment API and updated browser targets to "baseline-widely-available" standards.
- React: JavaScript library for building user interfaces. As of 2025, React 19.2 is current (released October 2025), featuring the Activity component, enhanced Chrome DevTools integration, and improved performance profiling.
- Vue: Progressive JavaScript framework. As of 2025, Vue 3.5.22 is current, with Vue 3.6 alpha introducing experimental Vapor Mode for reduced bundle sizes and improved performance.
- MessageBird Node.js SDK: Simplifies interaction with the MessageBird REST API for sending messages.
- dotenv: Module to load environment variables from a .env file into process.env, keeping sensitive credentials out of the codebase.
- (Optional) ngrok/localtunnel: Test webhooks locally if extending this application to receive messages (not the primary focus of sending MMS).
System Architecture:
graph TD
A[User/Client Application] -- HTTP POST Request --> B(Node.js/Express API Endpoint /send-mms);
B -- Uses MessageBird SDK --> C(MessageBird API);
C -- Delivers MMS --> D(Recipient's Mobile Device);
B -- Sends API Response --> A;
Prerequisites:
- Node.js LTS version. As of 2025, Node.js 22 is current (Active LTS until October 2025, Maintenance LTS until April 2027). Node.js 20.19+ remains supported. Vite 7 requires Node.js 20.19+ or 22.12+ minimum (Node.js 18 reached EOL in April 2025). Run node --version to check your installed version.
- A MessageBird account (sign up at MessageBird.com).
- A MessageBird API Key (Live Access Key).
- A MessageBird purchased number capable of sending MMS (check capabilities in the Dashboard). Virtual Mobile Numbers (VMN) or Toll-Free Numbers often support this, but check country/carrier restrictions.
- A publicly accessible URL for the media file you want to send (e.g., hosted on a CDN, S3 bucket, or public server). MessageBird needs to fetch the media from this URL.
1. Setting up the Project
Initialize your Node.js project and install dependencies.
- Create Project Directory: Open your terminal or command prompt and create a new directory for your project, then navigate into it.
mkdir node-messagebird-mms
cd node-messagebird-mms
- Initialize Node.js Project: Create a
package.jsonfile to manage dependencies and scripts.
npm init -y
- Install Dependencies: Install Express, the MessageBird SDK, and dotenv.
npm install express messagebird dotenv
- express: Web framework.
- messagebird: Official SDK for interacting with the MessageBird API.
- dotenv: Manages environment variables securely.
- Create Project Structure: Create the main application file and environment variable files.
touch index.js .env .env.example .gitignore
- index.js: Main application code.
- .env: Stores sensitive credentials (API Key, Originator Number). Never commit this file to version control.
- .env.example: Template showing required environment variables (safe to commit).
- .gitignore: Specifies files/directories Git should ignore.
- Configure
.gitignore: Addnode_modulesand.envto prevent committing them.
# .gitignore
node_modules/
.env
*.log
- Configure
.env.example: Add placeholders for required environment variables.
# .env.example
MESSAGEBIRD_ACCESS_KEY=YOUR_MESSAGEBIRD_LIVE_API_KEY
MESSAGEBIRD_ORIGINATOR=YOUR_MESSAGEBIRD_MMS_ENABLED_NUMBER_OR_ALPHANUMERIC_SENDER_ID
- MESSAGEBIRD\_ACCESS\_KEY: Your Live API key from the MessageBird dashboard.
- MESSAGEBIRD\_ORIGINATOR: Phone number (in E.164 format, e.g., +12025550144) or approved Alphanumeric Sender ID you purchased/configured in MessageBird that's enabled for MMS.
- Configure
.env: Create a.envfile by copying.env.exampleand filling in your actual credentials.
cp .env.example .env
Edit .env with your real MessageBird Live API Key and Originator Number.
# .env
MESSAGEBIRD_ACCESS_KEY=live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
MESSAGEBIRD_ORIGINATOR=+12025550144
Security: Keep your .env file secure and never share it publicly.
2. Implementing Core MMS Sending Functionality
Integrate the MessageBird SDK to handle MMS sending logic.
- Obtaining MessageBird API Key:
- Log in to your MessageBird Dashboard.
- Navigate to the Developers section in the left-hand menu.
- Click the API access tab.
- If you don't have a key, click Add access key. Create or use a Live key, not a test key, for sending actual messages.
- Copy the generated Live access key.
- Obtaining MessageBird Originator:
- In the MessageBird Dashboard, navigate to Numbers.
- Purchase a number if you don't have one. Ensure the number's capabilities include MMS for target countries. Virtual Mobile Numbers (VMN) or Toll-Free Numbers are common choices.
- Copy the number in E.164 format (e.g., +12025550144).
- Alternatively, if approved and supported for MMS in the destination country, use an Alphanumeric Sender ID (max 11 characters). However, phone numbers are generally more reliable for MMS.
- Initialize SDK and Load Environment Variables: Open
index.jsand require dependencies, then initialize the MessageBird client using the API key from your environment variables.
'use strict';
require('dotenv').config();
const express = require('express');
const { initClient } = require('messagebird');
const app = express();
const port = process.env.PORT || 3000;
if (!process.env.MESSAGEBIRD_ACCESS_KEY || !process.env.MESSAGEBIRD_ORIGINATOR) {
console.error(""FATAL ERROR: MESSAGEBIRD_ACCESS_KEY or MESSAGEBIRD_ORIGINATOR is not defined in the .env file."");
console.error(""Please ensure you have a .env file with your MessageBird credentials."");
process.exit(1);
}
let messagebird;
try {
messagebird = initClient(process.env.MESSAGEBIRD_ACCESS_KEY);
console.log(""MessageBird SDK initialized successfully."");
} catch (error) {
console.error(""Failed to initialize MessageBird SDK:"", error);
process.exit(1);
}
app.use(express.json());
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} - ${req.method} ${req.path}`);
next();
});
const server = app.listen(port, () => {
console.log(`Server listening on port ${port}`);
console.log(`Using Originator: ${process.env.MESSAGEBIRD_ORIGINATOR}`);
});
const gracefulShutdown = (signal) => {
console.log(`\nReceived ${signal}. Closing HTTP server.`);
server.close(() => {
console.log('HTTP server closed.');
process.exit(0);
});
};
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
- Load dotenv first to make environment variables available.
- Initialize Express.
- Validate essential environment variables before initializing the SDK.
- Use initClient from the messagebird package, passing the API key. A try-catch block handles potential initialization errors.
- Add express.json() middleware to parse incoming JSON requests.
- Include a basic request logger for visibility.
- Start the server listening on the configured port and assign it to server.
- Add basic graceful shutdown handlers for SIGTERM and SIGINT.
3. Building the API Layer
Create the /send-mms endpoint.
- Define the POST Route: Add the following route handler within the
// --- Routes ---section inindex.js.
app.post('/send-mms', (req, res) => {
const { recipient, messageBody, mediaUrl } = req.body;
if (!recipient) {
return res.status(400).json({ error: 'Recipient phone number is required.' });
}
if (!/^\+[1-9]\d{1,14}$/.test(recipient)) {
return res.status(400).json({ error: 'Invalid recipient phone number format. Use E.164 (e.g., +12025550144).' });
}
if (!mediaUrl) {
return res.status(400).json({ error: 'Media URL is required for MMS.' });
}
try {
new URL(mediaUrl);
} catch (_) {
return res.status(400).json({ error: 'Invalid media URL format.' });
}
const params = {
originator: process.env.MESSAGEBIRD_ORIGINATOR,
recipients: [recipient],
body: messageBody || `MMS message sent at ${new Date().toLocaleTimeString()}`,
type: 'binary',
mediaUrls: [mediaUrl],
};
console.log(`Attempting to send MMS to ${recipient} with media: ${mediaUrl}`);
console.log('Payload:', JSON.stringify({ ...params, recipients: ['[REDACTED]'] }, null, 2));
messagebird.messages.create(params, (err, response) => {
if (err) {
console.error(""MessageBird API Error:"", err);
let statusCode = 500;
let errorMessage = 'Failed to send MMS due to an internal server error.';
if (err.errors && err.errors.length > 0) {
errorMessage = `MessageBird API Error: ${err.errors[0].description} (Code: ${err.errors[0].code})`;
if ([2, 9, 10, 21, 22, 25].includes(err.errors[0].code)) {
statusCode = 400;
} else if (err.errors[0].code === 7) {
statusCode = 402;
}
}
return res.status(statusCode).json({ error: errorMessage, details: err.errors });
}
console.log(""MessageBird API Success:"", response);
res.status(200).json({
message: `MMS potentially sent to ${response.recipients.totalSentCount} recipient(s).`,
messageId: response.id,
status: response.recipients.items[0].status,
details: {
id: response.id,
href: response.href,
direction: response.direction,
type: response.type,
originator: response.originator,
body: response.body,
reference: response.reference,
validity: response.validity,
gateway: response.gateway,
typeDetails: response.typeDetails,
datacoding: response.datacoding,
mclass: response.mclass,
scheduledDatetime: response.scheduledDatetime,
createdDatetime: response.createdDatetime,
recipients: {
totalCount: response.recipients.totalCount,
totalSentCount: response.recipients.totalSentCount,
totalDeliveredCount: response.recipients.totalDeliveredCount,
totalDeliveryFailedCount: response.recipients.totalDeliveryFailedCount,
items: response.recipients.items.map(item => ({
recipient: item.recipient,
status: item.status,
statusDatetime: item.statusDatetime,
messagePartCount: item.messagePartCount,
}))
}
}
});
});
});
app.use((err, req, res, next) => {
console.error(""Unhandled Error:"", err.stack || err);
const status = err.status || 500;
const message = process.env.NODE_ENV === 'production' ? 'Something broke on the server!' : err.message;
res.status(status).json({ error: message });
});
- The route listens for POST requests on /send-mms.
- It extracts recipient, messageBody, and mediaUrl from the JSON request body (req.body).
- Basic Input Validation: Checks if required fields are present and performs rudimentary format validation (E.164 for recipient, basic URL check). Robust validation is crucial for production.
- Payload Preparation: Constructs the params object required by messagebird.messages.create.
- originator comes from environment variables.
- recipients must be an array, even for one number.
- body is included (optional but good practice).
- type is set to 'binary'. This usually works for images/GIFs. If you encounter issues with specific carriers or media types, consult MessageBird documentation; 'premium' might be required.
- mediaUrls is an array containing the public URL of the media file.
- Optional parameters like reportUrl (for delivery reports) or referenceUrl can be added.
- Logging: The code logs the attempt and the payload (recipient number redacted in the example log).
- Sending: messagebird.messages.create(params, callback) sends the request.
- Callback Handling:
- If err exists, it logs the error and sends an appropriate error response (500 or potentially 400/402 based on the MessageBird error code). Returns structured error details.
- If successful (response exists), it logs the success and sends a 200 response with a structured subset of details from the MessageBird response.
- Catch-All Error Handler: A final middleware catches any unhandled errors in the request lifecycle, avoiding stack traces in production.
4. Integrating with Third-Party Services (MessageBird)
MessageBird-specific configuration:
- Configuration: Handle via the .env file (MESSAGEBIRD\_ACCESS\_KEY, MESSAGEBIRD\_ORIGINATOR).
- API Key Security: dotenv loads the key into process.env, preventing hardcoding. Exclude the .env file from Git via .gitignore. Ensure server-level permissions restrict access to this file.
- SDK Initialization: const messagebird = initClient(process.env.MESSAGEBIRD\_ACCESS\_KEY); securely uses the key.
- Dashboard Navigation:
- API Key: Dashboard β Developers β API access β Add/View access key (Use Live).
- Originator Number: Dashboard β Numbers β Buy a Number (Ensure MMS capability) or Manage Numbers.
- Environment Variables:
- MESSAGEBIRD\_ACCESS\_KEY: Your Live API key (e.g., live\_xxxxxxxx). Obtain from Dashboard β Developers β API access. Authenticates API requests.
- MESSAGEBIRD\_ORIGINATOR: Your purchased/configured MessageBird number or Alphanumeric Sender ID enabled for MMS (e.g., +12025550144). Obtain from Dashboard β Numbers. Used as the "From" address for the MMS.
5. Error Handling, Logging, and Retry Mechanisms
- Error Handling Strategy:
- Input Validation: Catch invalid requests early (missing fields, bad formats) and return 400 errors.
- SDK Initialization: Check for errors during initClient and exit gracefully if critical.
- API Call Errors: The messagebird.messages.create callback receives an err object. Inspect err.errors for specific MessageBird issues. Map MessageBird errors to appropriate HTTP status codes (e.g., auth errors -> 400/401, balance -> 402, rate limits -> 429, server errors -> 500/502).
- Unhandled Errors: A global Express error handler catches unexpected exceptions.
- Logging:
- Use console.log and console.error for simplicity in this example. For production, use a dedicated logging library (like Winston or Pino) to:
- Log to files or external services.
- Set log levels (info, warn, error).
- Use structured logging (JSON format) for easier parsing.
- Mask sensitive data (like recipient numbers, API keys if accidentally logged).
- Log key events: server start, incoming requests, payload before sending (masked), API success responses, API errors (full error object).
- Retry Mechanisms:
- The current implementation does not include automatic retries for the API call itself. MessageBird handles some level of retries on their end for delivery to the handset.
- For critical applications, if the API call to MessageBird fails due to transient issues (e.g., network timeout, temporary MessageBird 5xx error), you could implement a retry strategy within your Express app:
- Use libraries like async-retry.
- Implement exponential backoff (wait longer between retries).
- Limit the number of retries.
- Only retry on transient errors (5xx, network issues, specific retryable MessageBird codes), not permanent ones (4xx like invalid recipient, invalid key).
- Example Concept (using async-retry):
const retry = require('async-retry');
try {
const response = await retry(async (bail, attempt) => {
console.log(`Attempting MessageBird API call (attempt ${attempt})...`);
return new Promise((resolve, reject) => {
messagebird.messages.create(params, (err, res) => {
if (err) {
console.warn(`MessageBird API call failed (attempt ${attempt}):`, err);
const isPermanentError = err.errors && err.errors[0] &&
[2, 9, 10, 21, 22, 25, 7].includes(err.errors[0].code);
if (isPermanentError) {
bail(new Error(`Permanent MessageBird Error (Code ${err.errors[0].code}): ${err.errors[0].description}`));
return;
}
return reject(err);
}
resolve(res);
});
});
}, {
retries: 3,
factor: 2,
minTimeout: 1000,
maxTimeout: 10000,
onRetry: (error, attempt) => console.warn(`Retrying API call (attempt ${attempt}) due to: ${error.message || error}`)
});
console.log(""MessageBird API Success (after retries if any):"", response);
res.status(200).json({ });
} catch (err) {
console.error(""Failed to send MMS after retries or due to permanent error:"", err);
let finalStatusCode = 500;
let finalErrorMessage = 'Failed to send MMS after multiple attempts.';
if (err.message && err.message.startsWith('Permanent MessageBird Error')) {
finalErrorMessage = err.message;
if (err.message.includes('(Code 7)')) finalStatusCode = 402;
else finalStatusCode = 400;
} else if (err.errors && err.errors.length > 0) {
finalErrorMessage = `MessageBird API Error: ${err.errors[0].description} (Code: ${err.errors[0].code})`;
}
res.status(finalStatusCode).json({ error: finalErrorMessage, details: err.errors || err.message });
}
6. Database Schema and Data Layer (Not Applicable)
This specific guide focuses solely on the transient action of sending an MMS and does not require a database. If you were building a system to track sent messages, manage templates, handle inbound replies, or correlate delivery reports, you would integrate a database (e.g., PostgreSQL, MongoDB) with an ORM/ODM (like Prisma, Sequelize, Mongoose) here. This would involve defining schemas, migrations, and data access functions.
7. Security Features
- Input Validation: Already implemented basic checks. For production:
- Use a robust validation library (like joi, zod, express-validator).
- Strictly validate phone number formats (E.164).
- Validate URL formats thoroughly. Consider using URL constructor and checking protocols (http, https).
- Potentially add checks to prevent Server-Side Request Forgery (SSRF) if mediaUrl could be user-controlled in a broader context (e.g., allowlist domains, disallow private IPs). MessageBird's fetch might mitigate some risks, but validating input is best practice.
- API Key Security: Handled via .env and .gitignore. Ensure the server environment where this runs is secure. Consider secrets management solutions (like HashiCorp Vault, AWS Secrets Manager, Doppler, platform-native secrets) for production.
- Rate Limiting: Protect the /send-mms endpoint from abuse. Use libraries like express-rate-limit.
const rateLimit = require('express-rate-limit');
const mmsLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
message: { error: 'Too many MMS requests from this IP, please try again after 15 minutes' },
standardHeaders: true,
legacyHeaders: false,
});
app.use('/send-mms', mmsLimiter);
- Authentication/Authorization: The current API is open. For real applications, protect it:
- Implement API keys, JWT tokens, OAuth, or other mechanisms appropriate for your use case.
- Add middleware before the route handler (and before the rate limiter if the limit is per-user) to verify credentials.
- HTTPS: Always run your Node.js application behind a reverse proxy (like Nginx, Caddy, Traefik, or cloud provider load balancers) that handles TLS/SSL termination, ensuring traffic is encrypted via HTTPS. Configure security headers (e.g., HSTS).
- Dependency Security: Regularly audit dependencies for known vulnerabilities (npm audit or yarn audit) and update them. Use tools like Snyk or Dependabot.
- Helmet: Use the helmet middleware for Express to set various HTTP headers for security.
const helmet = require('helmet');
app.use(helmet());
8. Handling Special Cases (MMS Specific)
- Media URL Accessibility: The mediaUrl must be publicly accessible without authentication for MessageBird servers to fetch it. Private URLs, URLs requiring logins, or localhost URLs will fail.
- Media File Size/Type: MessageBird and downstream carriers impose limits on media file sizes and supported types. Carrier-specific limits as of 2025:
- Optimal Deliverability: Keep files under 500 KB to ensure delivery across all carriers. For time-sensitive campaigns, limit to 150 KB.
- Industry Standard: All operators reliably handle up to 300 KB, with most US and Canadian carriers supporting up to 1 MB.
- AT&T: Accepts media up to 1 MB.
- Verizon: Accepts images up to 1.2 MB and videos up to 3.5 MB (general media limit: 1.7 MB).
- T-Mobile: Accepts media up to 3 MB.
- Supported Formats: Common formats like JPEG, PNG, GIF, MP4, and PDF are typically supported. Sending unsupported or oversized files will fail, often with generic errors. Test with target carriers for specific requirements.
- Character Limits: While MMS supports longer text than SMS, there are still practical limits imposed by carriers and devices. Keep the body reasonably concise.
- Encoding: Ensure your media file uses standard encoding. Standard web formats (JPEG, PNG, GIF) are best.
- Originator Restrictions: MMS sending might be restricted from Alphanumeric Sender IDs in some countries (like the US). A purchased, MMS-capable phone number (VMN or Toll-Free) is often required. Using an invalid or restricted originator will result in an error (e.g., Code 9).
- Country/Carrier Support: MMS is not universally supported by all carriers in all countries, or support may be inconsistent. Sending may fail if the recipient's carrier doesn't support MMS or blocks it from certain originators. MessageBird provides some country-specific information, but carrier behavior can vary.
- Cost: MMS messages are typically significantly more expensive than SMS messages. Factor this into your application's economics and monitor your MessageBird balance.
9. Performance Optimizations (Less Critical for Simple Sending)
For this simple sending endpoint, performance is less critical than reliability and correctness. However, if handling high volume:
- Asynchronous Operations: Node.js is inherently async. The messagebird.messages.create call is non-blocking, allowing the server to handle other requests while waiting for MessageBird's response. Ensure no blocking operations exist in the request path.
- Payload Size: Keep request/response payloads minimal if possible, especially if bandwidth is a concern. The current response includes detailed info; tailor it if clients need less.
- Resource Usage: Monitor CPU/Memory usage under load. Use tools like pm2 for process management and clustering on multi-core machines.
- External API Latency: The main bottleneck will be the latency of the MessageBird API call. This is largely outside your direct control, beyond ensuring a good network connection from your server to MessageBird's endpoints. Retries (Section 5) can help with transient network issues.
- Connection Pooling: Not directly applicable here, but if interacting with databases or other services, use connection pooling. The MessageBird SDK likely handles its HTTP connections efficiently.
- Caching: Not directly applicable to the sending action itself. Caching might be used for configuration or templates if the application were more complex.
10. Monitoring, Observability, and Analytics
For production readiness:
- Health Checks: Implement a simple /health endpoint that returns a 200 OK status. Monitoring services (like Kubernetes probes, uptime checkers) can poll this to ensure the application is running and responsive.
app.get('/health', (req, res) => {
res.status(200).json({ status: 'UP', timestamp: new Date().toISOString() });
});
- Performance Metrics: Use APM (Application Performance Monitoring) tools (like Datadog, New Relic, Dynatrace, OpenTelemetry collectors) or Prometheus/Grafana to track:
- Request latency (p50, p90, p99 for /send-mms).
- Request rate (RPM/RPS).
- Error rates (4xx, 5xx breakdown by status code and route).
- Node.js process metrics (CPU, memory usage, event loop lag, garbage collection).
- Error Tracking: Integrate services like Sentry, Bugsnag, or Rollbar to capture, aggregate, and alert on application errors (caught and uncaught) in real-time, providing stack traces and context.
- Logging Aggregation: Send structured logs (using Winston/Pino) to a central logging platform (like Elasticsearch/Logstash/Kibana (ELK), Datadog Logs, Splunk, Grafana Loki) for searching, analysis, and alerting based on log patterns.
- MessageBird Dashboard: Regularly check the MessageBird Message Logs (or use their Insights API) for insights into sending volume, delivery rates, costs, and specific errors reported by carriers that might not surface directly in your API response.
- Delivery Reports (DLRs): For reliable status tracking, configure a reportUrl in your messages.create payload (or globally in MessageBird settings). This URL points to an endpoint you create in your Express app to receive webhooks about the final delivery status (e.g., delivered, failed, expired). Process these DLRs asynchronously, potentially updating a database record associated with the original message ID.
11. Troubleshooting and Caveats
- Error:
Request not allowed (incorrect access_key)(Code: 2) - Cause: Invalid or incorrect MESSAGEBIRD\_ACCESS\_KEY in .env. Using a Test key instead of a Live key (or vice-versa). Key lacks permissions.
- Solution: Verify the key in .env matches the Live key in the MessageBird Dashboard (Developers -> API access). Ensure .env is being loaded correctly (check for typos, restart server). Confirm the key is active and has message sending permissions.
- Error:
originator is invalidorThe originator is not allowed to send this type of message(Code: 9 or similar) - Cause: The MESSAGEBIRD\_ORIGINATOR number/ID in .env is incorrect, not owned by your account, misspelled, or not capable of sending MMS to the target country/carrier (e.g., using Alphanumeric where a number is required, number lacks MMS capability).
- Solution: Verify the originator in .env. Check the number's capabilities in the MessageBird Dashboard (Numbers -> Manage). Ensure it's MMS-enabled for the destination. Use the full E.164 number format (+1...) if using a phone number.
- Error:
recipient is invalid(Code: 10) - Cause: The recipient number provided in the API request is not in valid E.164 format, is blacklisted, or is otherwise considered invalid by MessageBird or the downstream carrier.
- Solution: Ensure the client sends the recipient number with a leading + and country code (e.g., +12025550189). Add stricter validation on your server. Check MessageBird logs for more details if the format seems correct.
- Error related to
mediaUrlsor fetching media (may vary, e.g.,File not accessible,Content type not supported, Code: 20) - Cause: The mediaUrl is not publicly accessible (behind login, firewall, private IP), incorrect URL, points to an unsupported file type, or the file exceeds size limits. Network issues between MessageBird's servers and the media host. SSL/TLS issues on the media host.
- Solution: Verify the URL is public (try opening it in an incognito browser tab). Check file size and type against MessageBird/carrier limits (aim for common types like JPEG/PNG/GIF under 1-2MB as a safe starting point). Ensure the media hosting server is reliable and uses valid HTTPS.
- Messages Not Received (but API shows success/accepted):
- Cause: Carrier filtering (spam, content), recipient device issues (no MMS plan, poor signal, unsupported device, blocked sender), incorrect recipient number (typo), country/carrier MMS limitations or temporary outages.
- Solution: Double-check the recipient number. Test with different recipients/carriers if possible. Check MessageBird Message Logs for detailed status codes/errors provided by the downstream carrier (these arrive later). Implement Delivery Reports (DLRs) via reportUrl for definitive status updates. Consult MessageBird support with specific message IDs if the issue persists and logs/DLRs don't clarify.
- MMS Cost: Remember MMS messages cost significantly more than SMS. Monitor your MessageBird balance (Error Code 7 indicates insufficient funds).
- Rate Limits: MessageBird imposes API rate limits (check their documentation). High-volume sending may require contacting them or implementing throttling/queuing on your end. The express-rate-limit middleware helps protect your own API endpoint, not MessageBird's limits directly.
- Asynchronous Nature: Message delivery is asynchronous. A successful API response (200 OK with status accepted or scheduled) means MessageBird accepted the request, not that the message was delivered. Use Delivery Reports (reportUrl) for final delivery status confirmation.
12. Deployment and CI/CD
- Environment Configuration: Do not commit your .env file. Production deployment environments (Heroku, AWS ECS/EKS, Google Cloud Run, Azure App Service, Docker Swarm, etc.) provide mechanisms to securely inject environment variables. Use these platform-specific methods (e.g., ConfigMaps/Secrets in K8s, Task Definition environment variables in ECS, App Settings in Azure).
- Process Management: Use a process manager like pm2 to run your Node.js application reliably in production. pm2 handles:
- Running the app in the background.
- Monitoring and automatic restarts on crashes.
- Clustering (running multiple instances to utilize multi-core servers).
- Log management.
- Graceful shutdowns/reloads.
- Example
pm2usage: - Install: npm install pm2 -g
- Start clustered: pm2 start index.js -i max --name messagebird-mms-api --watch (use --watch cautiously in prod, prefer CI/CD restarts)
- Manage: pm2 list, pm2 logs messagebird-mms-api, pm2 stop/restart/delete messagebird-mms-api, pm2 reload messagebird-mms-api (graceful reload)
- Consider using a ecosystem.config.js file for pm2 configuration.
- Reverse Proxy: Deploy behind a web server/reverse proxy like Nginx, Caddy, Traefik, or a cloud load balancer. Benefits include:
- SSL/TLS termination (HTTPS).
- Load balancing across pm2 cluster instances.
- Serving static files (if any).
- Basic caching or request buffering.
- Easier IP allow/deny listing.
- CI/CD Pipeline (Conceptual):
- Commit: Developer pushes code to a Git repository (GitHub, GitLab, Bitbucket).
- Trigger: Push triggers a CI/CD pipeline (e.g., GitHub Actions, Jenkins, GitLab CI, CircleCI).
- Build & Test:
- Checks out code.
- Installs dependencies using lockfile (npm ci or yarn install --frozen-lockfile).
- Runs linters (eslint .).
- Runs automated tests (Unit, Integration - see section 13).
- (Optional) Performs security scans (npm audit --production).
- Builds artifacts (e.g., creates a production build if needed, builds a Docker image).
- Deploy:
- Pushes Docker image to a registry (Docker Hub, ECR, GCR, ACR).
- Deploys the new version to the hosting environment (e.g., updates Kubernetes deployment, triggers an ECS service update, pushes to Heroku/Cloud Run), ensuring production environment variables are securely configured in the target environment.
- Containerization (Docker): Consider packaging the application as a Docker image for consistent environments and easier deployment. Create a Dockerfile.
- Rollback Strategy: Have a procedure to quickly redeploy the previously known-good version in case of deployment issues. CI/CD tools often support automated or manual rollbacks. Versioning artifacts (like Docker images with Git commit SHAs) is crucial.
Frequently Asked Questions (FAQ)
Q: How do I send MMS with Node.js and MessageBird? A: Send MMS with Node.js by installing
the MessageBird SDK and Express framework, creating a POST endpoint that accepts recipient numbers and media
URLs, then calling messagebird.messages.create() with the mediaUrls parameter.
Configure your MessageBird API key via environment variables and ensure you have an MMS-capable originator
number.
Q: What file size limits apply to MMS messages? A: MMS file size limits vary by carrier. For optimal deliverability, keep files under 500 KB. AT&T accepts up to 1 MB, Verizon accepts images up to 1.2 MB and videos up to 3.5 MB, and T-Mobile accepts up to 3 MB. All carriers reliably handle files up to 300 KB. For time-sensitive campaigns, limit files to 150 KB.
Q: What media formats are supported for MMS? A: MMS supports common formats including JPEG, PNG, GIF for images, MP4 for videos, and PDF for documents. The MessageBird API requires publicly accessible URLs for media files β the service fetches media from your URL during message delivery. Unsupported formats or oversized files will fail with generic errors.
Q: Do I need a special phone number to send MMS with MessageBird? A: Yes, you need a MessageBird phone number with MMS capabilities. Purchase a Virtual Mobile Number (VMN) or Toll-Free Number from the MessageBird Dashboard and verify it supports MMS for your target countries. Alphanumeric Sender IDs have limited MMS support and may not work in regions like North America.
Q: How do I handle MessageBird API errors in Node.js? A: Handle MessageBird errors by
wrapping the SDK callback in a Promise, using try/catch blocks, and checking the error.errors
array structure. MessageBird returns error codes and descriptions β map authentication errors to 400/401
status codes, insufficient balance to 402, and server errors to 500. Log full error objects for debugging.
Q: Why are my MMS messages not being delivered? A: MMS delivery failures typically occur due to: (1) media files not publicly accessible, (2) file sizes exceeding carrier limits, (3) unsupported media formats, (4) originator number lacking MMS capabilities, (5) recipient carrier blocking MMS, or (6) incorrect recipient phone number format. Check MessageBird Dashboard logs for detailed delivery status and carrier-specific errors.
Q: Can I send MMS to multiple recipients at once? A: Yes, include multiple phone numbers in
the recipients array parameter when calling messagebird.messages.create(). Example:
recipients: ['+12005550199', '+447123456789']. MessageBird charges per recipient, and each
receives the same message and media. For personalized messages to multiple recipients, send separate API
requests.
Q: What's the difference between MMS and SMS in Node.js? A: MMS (Multimedia Messaging
Service) supports images, videos, GIFs, and PDFs alongside text, while SMS only supports plain text. MMS
requires the mediaUrls parameter and an MMS-capable originator number. MMS messages are
significantly more expensive than SMS and have carrier-specific file size limits. Use MMS for rich media
campaigns and SMS for simple text notifications.
Q: How do I test MMS sending without incurring costs? A: Test MMS sending using MessageBird's Test API key for development (messages simulate delivery without actually sending). For real testing, send to your own phone number with small file sizes to minimize costs. MessageBird doesn't charge for failed deliveries. Check the Dashboard SMS Log to verify message status without waiting for physical delivery.
Q: What Node.js version is required for MessageBird MMS? A: MessageBird Node.js SDK works with Node.js 14+, but for modern features and security, use Node.js 22 LTS (Active LTS until October 2025, Maintenance until April 2027). If using Vite 7 for frontend integration, you need Node.js 20.19+ or 22.12+ minimum since Node.js 18 reached end-of-life in April 2025.
Q: How do I implement retry logic for failed MMS deliveries? A: Implement retry logic using
the async-retry package with exponential backoff. Only retry transient errors (5xx, network
timeouts) β don't retry permanent errors (4xx like authentication failures, invalid recipients). Set retry
limits (3β5 attempts) with increasing delays (1s, 2s, 4s). Check the error code to distinguish permanent from
transient failures.
Q: Can I track MMS delivery status in real-time? A: Yes, implement delivery reports (DLRs)
by configuring a reportUrl parameter in your messages.create call. This webhook URL
receives status updates (delivered, failed, expired) from MessageBird. Create an Express endpoint to receive
these webhooks, validate them, and update your database records with final delivery status for each message.
13. Verification and Testing
- Manual Verification:
- Verify your
.envfile contains the correct Live API Key and an MMS-capable Originator number. - Upload a sample image (JPEG, PNG, GIF, or small MP4) to a publicly accessible URL (use Imgur for testing, or your own public server/CDN/S3 bucket with public read access). Keep the file size small (< 1 MB) for initial tests.
- Start the server locally:
node index.js - Use
curl, Postman, or Insomnia to send a POST request to your running server (http://localhost:3000/send-mmsby default):
curl -X POST http://localhost:3000/send-mms \
-H "Content-Type: application/json" \
-d '{
"recipient": "+1xxxxxxxxxx",
"messageBody": "Node.js MMS Test from curl!",
"mediaUrl": "YOUR_PUBLICLY_ACCESSIBLE_MEDIA_URL"
}'
Replace +1xxxxxxxxxx with your actual mobile number (E.164 format) capable of receiving MMS, and
YOUR_PUBLICLY_ACCESSIBLE_MEDIA_URL with the URL from step 2.
- Check your server logs for output (initialization, request received, payload, API response/error).
- Check the response from
curl/Postman (should be 200 OK with message details on success, or an error JSON). - Check your mobile phone for the MMS message (may take a few seconds to minutes).
- Check the MessageBird Dashboard Logs for the message status.
- Automated Testing (Conceptual):
- Unit Tests: Use Jest or Mocha/Chai to test individual functions or modules in isolation. Mock dependencies like the messagebird SDK to avoid making real API calls during unit tests. Test input validation logic, payload construction, etc.
- Integration Tests: Test the interaction between different parts of your application, including the API endpoint. Use supertest to make HTTP requests to your running Express app (in a test environment). You might still mock the final messagebird.messages.create call to avoid sending actual MMS and incurring costs during tests, but verify that your endpoint calls the SDK correctly with the expected parameters based on the request input.
- End-to-End (E2E) Tests: (Use sparingly, can be slow/expensive) Deploy the application to a staging environment and use a test MessageBird key/number (if available) or carefully manage live tests to send a real MMS. Automate verification of receipt on a physical device (difficult). Focus on critical paths.
- Testing Edge Cases:
- Invalid recipient formats.
- Missing required fields (recipient, mediaUrl).
- Invalid mediaUrl (malformed, non-existent, private).
- Large media files (if you know the limits).
- Unsupported media types.
- Empty messageBody.
- Test API error handling by mocking different error responses from the MessageBird SDK.
- Test rate limiting if implemented.
Simpler Alternative: Send the Same SMS With SMSRoute (No-KYC, Direct Routes)
If you want to replace legacy aggregator SDK boilerplate, multi-week compliance queues, and opaque carrier surcharges with a single HTTP request, SMSRoute delivers global SMS over direct Tier-1 carrier interconnects with instant API access and transparent per-country pricing.
curl -X POST https://api.sendsmsnokyc.com/messages \
-H "x-api-key: $SMSROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": ["+14155551234"],
"channel": ["sms"],
"body": "Your verification code is 482910"
}'
- Instant onboarding: No KYC paperwork or sales queues β grab an API key and fund with crypto (BTC/USDT) or card.
- Direct Tier-1 routes: Verify real handset delivery, DLR latency, and Sender ID preservation before launch via SMSRoute Live Carrier Testing.
- Transparent global pricing: Compare exact per-country termination rates on our live pricing page.
Ship Global SMS in One API Call
Skip legacy SDK sprawl and carrier bottlenecks. Send OTPs, alerts, and bulk campaigns across 190+ countries with SMSRoute.
Explore SMSRoute Developers β