SMS Gateway for Android
repository·master·Indexed 26 days ago
https://github.com/capcom6/android-sms-gatewayA programmable SMS gateway that turns an Android smartphone into a gateway for sending and receiving SMS, MMS, and Data SMS via APIs, CLI tools, and webhooks. It supports Local Server and Cloud Server modes, end-to-end encryption, and real-time event notifications for 2FA, transactional messaging, and IoT commands. Requires Android 5.0 or above.
What's inside android-sms-gateway
- SMS Gateway turns an Android smartphone into an SMS gateway. It allows you to send and receive SMS, MMS, and Data SMS messages programmatically via an API or CLI tool. It supports real-time webhooks for incoming messages and provides end-to-end encryption for message content and recipient phone numbers.
Choose the correct Build Variant
masterThe project offers two pre-built variants:
- Secure (release) build: Recommended for production deployments. It includes strict security configurations.
- Insecure build: Intended only for development and testing. It allows cleartext traffic. Never use this build in public environments.
Configure and use Webhooks for messaging events
masterWebhooks allow you to receive POST notifications for messaging events (SMS/MMS) directly from the device.
Supported Events
sms:received: SMS message receivedsms:sent: SMS message sentsms:delivered: SMS message deliveredsms:failed: SMS message failed to sendsms:data-received: Data SMS receivedmms:received: MMS notification received (before download)mms:downloaded: MMS fully downloaded with body and attachmentssystem:ping: Periodic heartbeat
Setup Steps
- Prepare an HTTP server with a valid SSL certificate.
- Register the webhook via a POST request to the
/webhooksendpoint (usehttp://<device_local_ip>:8080/webhooksfor Local mode orhttps://api.sms-gate.app/3rdparty/v1/webhooksfor Cloud mode). - To deregister, send a DELETE request to
/webhooks/<unique-id>.
Note: The device must have an outgoing internet connection to dispatch webhooks.
# Register a webhook curl -X POST -u <username>:<password> \ -H "Content-Type: application/json" \ -d '{ "id": "unique-id", "url": "https://webhook.site/<your-uuid>", "event": "sms:received" }' \ http://<device_local_ip>:8080/webhooks # Deregister a webhook curl -X DELETE -u <username>:<password> \ http://<device_local_ip>:8080/webhooks/unique-idInstall SMS Gateway via APK
masterTo install the application on an Android device:
- Download the latest APK from the Releases page.
- Transfer the APK to your Android device.
- Enable Unknown sources in your device's Settings > Security (or Privacy).
- Use a file manager to locate the APK and tap it to install.
- Follow the on-screen prompts to complete the installation.
https://github.com/capcom6/android-sms-gateway/releasesUse Cloud Server mode to send SMS
masterCloud Server mode is used when dealing with dynamic or shared device IP addresses.
- Launch the app on your device.
- Toggle the
Cloud Serverswitch to "on". - Tap the
Onlinebutton to connect to the cloud server. - Retrieve the basic authentication credentials (
<username>and<password>) from theCloud Serversection in the app.
To send a message, use a
curlcommand or the CLI tool targeting the cloud API endpoint.curl -X POST -u <username>:<password> \ -H "Content-Type: application/json" \ -d '{ "textMessage": { "text": "Hello, doctors!" }, "phoneNumbers": ["+19162255887", "+19162255888"] }' \ https://api.sms-gate.app/3rdparty/v1/messageUse Local Server mode to send SMS via local network
masterLocal Server mode is ideal for sending messages from within a local network.
- Launch the app on your device.
- Toggle the
Local Serverswitch to "on". - Tap the
Offlinebutton to activate the server. - Retrieve the device's local IP address and basic authentication credentials (
<username>and<password>) from theLocal Serversection in the app.
To send a message, use a
curlcommand or the CLI tool targeting the device's local IP on port 8080.curl -X POST -u <username>:<password> \ -H "Content-Type: application/json" \ -d '{ "textMessage": { "text": "Hello, doctors!" }, "phoneNumbers": ["+19162255887", "+19162255888"] }' \ http://<device_local_ip>:8080/messagePrerequisites and Permissions for SMS Gateway
masterPrerequisites
- An Android device running Android 5.0 (Lollipop) or above.
Required and Optional Permissions
To function correctly, the app requires or benefits from the following permissions:
Permission Requirement Purpose SEND_SMSRequired Required to send SMS messages. READ_PHONE_STATEOptional Allows selecting specific SIM cards. READ_SMSOptional Allows reading previously received SMS messages. RECEIVE_SMSOptional Required to trigger webhooks on incoming SMS. RECEIVE_MMSOptional Required to trigger webhooks on incoming MMS. RECEIVE_WAP_PUSHOptional Required to trigger webhooks on incoming MMS. Reference: Webhook Payload Format
masterWhen a webhook event is triggered, the application dispatches a POST request with a JSON payload. Example for
sms:received:{ "event": "sms:received", "payload": { "messageId": "msg_12345abcde", "message": "Received SMS text", "phoneNumber": "+19162255887", "simNumber": 1, "receivedAt": "2024-06-07T11:41:31.000+07:00" } }Represent received messages with InboxMessage
masterThe
InboxMessagesealed class is the base type for all incoming messages. It contains common properties for any received message:address(sender),date(timestamp), and an optionalsubscriptionId(SIM card identifier).Depending on the message type, you can use one of the following subclasses:
Text: For standard SMS text messages. Contains atextstring.Data: For binary data messages. Contains adatabyte array.MmsHeaders: Metadata for an MMS message. ContainsmessageId,transactionId,subject,size, andcontentClass.MMS: For Multimedia messages. ContainsmessageId,body,subject, and a list ofAttachmentobjects.
SmsEventPayload webhook payload structures
masterWhen consuming webhooks from the Android SMS Gateway, SMS event notifications are delivered using one of several specialized payload classes derived from
SmsEventPayload. These payloads provide details about the lifecycle of an SMS message (sent, delivered, failed, received, etc.).Common fields across all payloads include:
messageId: Unique identifier for the message.sender: The sender's phone number.recipient: The recipient's phone number.simNumber: The index of the SIM card used (if applicable).phoneNumber: The primary phone number associated with the event (either sender or recipient depending on the event type).
// Available SmsEventPayload subclasses: class SmsSent( messageId: String, sender: String?, recipient: String, simNumber: Int?, val partsCount: Int, val sentAt: Date ) class SmsDelivered( messageId: String, sender: String?, recipient: String, simNumber: Int?, val deliveredAt: Date ) class SmsFailed( messageId: String, sender: String?, recipient: String, simNumber: Int?, val failedAt: Date, val reason: String ) class SmsReceived( messageId: String, sender: String, recipient: String?, simNumber: Int?, val message: String, val receivedAt: Date ) class SmsDataReceived( messageId: String, sender: String, recipient: String?, simNumber: Int?, val data: String, val receivedAt: Date ) class SmsCancelled( messageId: String, sender: String?, recipient: String, simNumber: Int?, val cancelledAt: Date )Access MMS attachments via MMS.Attachment
masterWhen handling an
MMStypeInboxMessage, you can access its multimedia components through theattachmentslist. EachAttachmentobject provides details about a specific part of the MMS:partId: Unique identifier for the part.contentType: The MIME type of the attachment (e.g.,image/jpeg).name: The filename of the attachment.size: The size of the attachment in bytes.data: The attachment content represented as a string.