/android-sms-gateway

The SMS Gateway for Android™ app enables sending and receiving SMS messages through an API that can be accessed directly on the device or via a cloud server when direct device access is not possible.

Primary LanguageKotlinApache License 2.0Apache-2.0

Contributors Forks Stargazers Issues Apache 2.0 License


Logo

SMS Gateway for Android™

Turns your smartphone into an SMS gateway for sending messages via API.
Explore the docs »

Report Bug · Request Feature

About The Project

SMS Gateway turns your Android smartphone into an SMS gateway. It's a lightweight application that allows you to send SMS messages programmatically via an API or CLI tool and receive webhooks on incoming SMS. This makes it ideal for integrating SMS functionality into your own applications or services.

Features

  • No registration required: No registration or email is required to create an account. In local mode, you don't need an account at all!
  • Send SMS via API: Use our API to send messages directly from your applications or services.
  • Support for Android 5.0 and above: The application is compatible with Android 5.0 and later versions.
  • Message status tracking: Monitor the status of sent messages in real-time.
  • Automatic startup: The application starts running as soon as your device boots up.
  • Support for multiple SIM cards: The application supports devices with multiple SIM cards.
  • Multipart messages: The application supports sending long messages with auto-partitioning.
  • End-to-end encryption: The application provides end-to-end encryption by encrypting message content and recipients' phone numbers before sending them to the API and decrypting them on the device.
  • Message expiration: The application allows setting an expiration time for messages. Messages will not be sent if they have expired.
  • Random delay between messages: Introduces a random delay between sending messages to avoid mobile operator restrictions.
  • Private server support: The application allows for the use of a backend server in the user's infrastructure for enhanced security.
  • App status reporting: Ability to report current app status by sending requests to specified URL at any user-defined intervals.
  • Webhooks on incoming SMS: The application allows setting up webhooks to be sent to a specified URL whenever an SMS is received.

Ideal For

  • Authentication & Verification: Secure user accounts and transactions with SMS-based two-factor authentication, minimizing the risk of unauthorized access.
  • Transactional Messages: Send confirmation messages for user actions, enhancing the reliability and perception of your brand.
  • SMS Reminders: Prompt users about upcoming events or appointments to ensure engagement and reduce missed opportunities.
  • SMS Notifications: Deliver immediate notifications to users for important updates, offers, and service enhancements.
  • User Feedback: Solicit and collect user feedback through SMS, providing valuable insights for improving your services.

Note: It is not recommended to use this for batch sending due to potential mobile operator restrictions.

(back to top)

Built With

  • Kotlin
  • Ktor
  • Room
  • Firebase

(back to top)

Installation

You can install app to your device from prebuilt APK or by building from sources.

Prerequisites

You need an Android device with Android 5.0 (Lollipop) or above for using the application.

Permissions

To use the application, you need to grant the following permissions:

  • SEND_SMS: This permission is required to send SMS messages.
  • READ_PHONE_STATE: This permission is optional. If you want to select the SIM card, you can grant this permission.
  • RECEIVE_SMS: This permission is optional. If you want to receive webhooks on incoming SMS, you need to grant this permission.

Installation from APK

  1. Navigate to the Releases page.
  2. Download the latest APK file from the list of available releases.
  3. Transfer the APK file to your Android device.
  4. On your Android device, go to Settings > Security (or Privacy on some devices).
  5. Enable the Unknown sources option to allow installation of apps from sources other than the Play Store.
  6. Use a file manager app to navigate to the location of the downloaded APK file.
  7. Tap on the APK file to start the installation process.
  8. Follow the on-screen prompts to complete the installation.

(back to top)

Getting Started

For integration examples, please refer to the CLI Tool Documentation and API Documentation

The SMS Gateway for Android can work in two modes: with a Local Server started on the device or with a Cloud Server. The basic API is the same for both modes and is documented on the SMS Gateway for Android API Documentation page.

Local Server

Local server example settings

This mode is ideal for sending messages from a local network.

  1. Launch the app on your device.

  2. Toggle the Local Server switch to the "on" position.

  3. Tap the Offline button at the bottom of the screen to activate the server.

  4. In the Local Server section, your device's local and public IP addresses will be displayed, along with the credentials for basic authentication. Note that the public IP address is only accessible if you have a public (or "white") IP and your firewall is configured correctly.

    Example settings for Local Server mode
  5. To send a message from within the local network, execute a curl command like the one below. Replace <username>, <password>, and <device_local_ip> with the actual values provided in the previous step:

    curl -X POST -u <username>:<password> \
      -H "Content-Type: application/json" \
      -d '{ "message": "Hello, doctors!", "phoneNumbers": ["+19162255887", "+19162255888"] }' \
      http://<device_local_ip>:8080/message

    Alternatively, you can use the CLI Tool:

    smsgate -e 'http://<device_local_ip>:8080/message' -u <username> -p <password> \
      send --phones '+19162255887,+19162255888' 'Hello, doctors!'

Cloud Server

Cloud server example settings

Use the cloud server mode when dealing with dynamic or shared device IP addresses.

  1. Launch the app on your device.

  2. Toggle the Cloud Server switch to the "on" position.

  3. Tap the Online button located at the bottom of the screen to connect to the cloud server.

  4. In the Cloud Server section, the credentials for basic authentication will be displayed.

    Example settings for Cloud Server mode
  5. To send a message via the cloud server, perform a curl request with a command similar to the following, substituting <username> and <password> with the actual values obtained in step 4:

    curl -X POST -u <username>:<password> \
      -H "Content-Type: application/json" \
      -d '{ "message": "Hello, doctors!", "phoneNumbers": ["+19162255887", "+19162255888"] }' \
      https://api.sms-gate.app/3rdparty/v1/message

Or with CLI:

```sh
smsgate -u <username> -p <password> \
  send --phones '+19162255887,+19162255888' 'Hello, doctors!'
```

For further privacy, you can deploy your own private server. See the Private Server section for more details.

Webhooks

Webhooks can be utilized to get notifications of incoming SMS messages.

Follow these steps to set up webhooks:

  1. Set up your own HTTP server with a valid SSL certificate to receive webhooks. For testing purposes, webhook.site can be useful.

  2. Register your webhook with an API request:

    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
  3. Send an SMS to the device.

  4. The application will dispatch POST request to the specified URL with a payload such as:

    {
      "event": "sms:received",
      "payload": {
        "message": "Received SMS text",
        "phoneNumber": "+19162255887",
        "receivedAt": "2024-06-07T11:41:31.000+07:00"
      }
    }
  5. To deregister a webhook, execute a curl request using the following pattern:

    curl -X DELETE -u <username>:<password> \
      http://<device_local_ip>:8080/webhooks/unique-id

For cloud mode the process is similar, simply change the URL to https://api.sms-gate.app/3rdparty/v1/webhooks. Webhooks in Local and Cloud mode are independent.

Note: Webhooks are transmitted directly from the device; therefore, the device must have an outgoing internet connection. As the requests originate from the device, incoming messages remain inaccessible to us.

(back to top)

Roadmap

  • Add functionality to modify user credentials.
  • Introduce option to adjust the local server port.
  • Send notifications to an external server when the status of a message changes.
  • Incorporate scheduling capabilities for dispatching messages at specific times.
  • Implement region-based restrictions to prevent international SMS.
  • Provide an API endpoint to retrieve the list of available SIM cards on the device.
  • Include detailed error messages in responses and logs.

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the Apache-2.0 license. See LICENSE for more information.

(back to top)

Contact

If you have any questions or suggestions, feel free to reach out through the following channels:

Links

(back to top)