SMS Gateway is an Android application that captures incoming SMS messages, filters them based on customizable rules, and forwards them to specified email addresses or API endpoints. This application is ideal for monitoring important notifications, security alerts, or business messages without constantly checking your phone.
- SMS Interception: Instantly captures incoming SMS messages using Android's BroadcastReceiver system
- Customizable Filtering: Create filter rules with pattern matching to process only relevant messages
- Email Forwarding: Automatically forwards filtered messages to configured email addresses
- API Integration: Send SMS data to custom API endpoints for further processing or integration with other systems
- Background Processing: Reliable background operation with WorkManager integration
- Message Storage: Stores all messages locally with Room database for reference and status tracking
- Clean Architecture: Built using MVVM architecture with use cases and repositories
- Modern UI: Intuitive user interface built with Jetpack Compose
SMS Gateway follows clean architecture principles with a focus on separation of concerns:
com.emrepbu.smsgateway/
βββ data/ # Data layer (repositories implementation, data sources)
β βββ local/ # Local database implementation with Room
β βββ remote/ # Remote data services (email sending, API)
β β βββ api/ # API service integration
β β β βββ model/ # API data models
β β β βββ service/# Ktor API service implementation
β β βββ email/ # Email service implementation
β βββ repository/ # Repository implementations
βββ di/ # Dependency injection modules
βββ domain/ # Domain layer (business logic)
β βββ model/ # Domain models
β βββ repository/ # Repository interfaces
β βββ usecase/ # Use cases for application functionality
βββ receiver/ # SMS broadcast receiver
βββ ui/ # Presentation layer
β βββ components/ # Reusable UI components
β βββ navigation/ # Navigation components
β βββ screens/ # Application screens
β β βββ ApiConfigScreen.kt # API configuration screen
β βββ state/ # UI state definitions
β βββ theme/ # Application theme
β βββ viewmodel/ # ViewModels
βββ utils/ # Utility classes
βββ work/ # WorkManager implementation
βββ MainActivity.kt # Main activity
βββ SmsGatewayApp.kt # Application class
sequenceDiagram
participant OS as Android OS
participant SR as SmsReceiver
participant WM as WorkManager
participant PW as ProcessSmsWorker
participant Repo as Repository
participant UC as Use Cases
participant API as API Service
participant Email as Email Service
OS->>SR: 1. SMS_RECEIVED_ACTION
SR->>WM: 2. enqueue(processWorkRequest)
WM->>PW: 3. doWork()
PW->>Repo: 4. insertMessage(sms)
Repo-->>PW: 5. success
PW->>UC: 6. processNewSmsUseCase(sms)
UC->>UC: 7. applyFilterUseCase()
alt API forwarding enabled
UC->>UC: 8. sendSmsToApiUseCase()
UC->>API: 9. sendSmsData(sms)
API-->>UC: 10. ApiResponse
else Email forwarding enabled
UC->>UC: 11. sendEmailForSmsUseCase()
UC->>Email: 12. sendEmail(sms)
Email-->>UC: 13. EmailResult
end
UC-->>PW: 14. ForwardResult
PW->>Repo: 15. updateSmsForwardStatus(id, true)
Note over OS,UC: Key Points:<br/>- SMS processing happens in background using WorkManager for reliability<br/>- Clean architecture separates concerns: UI, business logic, and data access<br/>- Messages can be forwarded to API endpoints or email addresses
When an SMS is received, the following process takes place:
SmsReceiver
captures the incoming message via theSMS_RECEIVED_ACTION
broadcast.- Message details are extracted and passed to a
WorkManager
task. ProcessSmsWorker
stores the message in the local database and calls theProcessNewSmsUseCase
.- Filter rules are applied to check if the message matches any criteria.
- If there are matches, the message is forwarded to the corresponding email addresses and/or API endpoints.
- The message status is updated in the database.
The filter system allows users to create rules based on:
- Sender phone number (exact match or partial patterns)
- Message content (keywords, phrases, or regex patterns)
- Message type
- Priority levels
SMS Gateway uses Jakarta Mail to send emails with:
- Customizable email subjects
- SMS content in the email body
- Sender information
- Timestamp information
- Optional email templates
SMS Gateway can forward SMS data to custom API endpoints using Ktor:
- Configurable API URL and authentication parameters
- JSON payload with SMS data
- HTTP request customization (headers, method)
- Response handling and error management
- Automatic retry for failed requests
- Support for various authentication methods (Basic, Bearer token, etc.)
- Connection pooling and timeout configuration for reliable communication
- Android 9.0 (API level 28) or higher
- SMS permissions granted
- Internet connection for email forwarding and API communication
- Configured email service settings
- API endpoint (if using API integration)
- All messages are stored only on your device
- Email and API configuration is stored securely
- No data is sent to external servers except for authorized email forwarding or API endpoints
- Filter processing happens entirely on-device
- API communication uses HTTPS for secure data transmission
- Options for custom security headers and authentication tokens
- Install the SMS Gateway application
- Grant required permissions (SMS reading and Internet)
- Configure your filter rules
- Set up email forwarding options and/or API endpoint details
- The app will now automatically process incoming messages
The app features a clean, modern interface built with Jetpack Compose:
- Home screen displays all received messages with forwarding status
- Filter rule editor for creating and managing filtering criteria
- Email configuration screen for setting up forwarding destinations
- API configuration screen for setting up API integration
- Settings screen for general application configurations
- Language: Kotlin
- UI Framework: Jetpack Compose
- Architecture: MVVM with Clean Architecture
- Dependency Injection: Hilt
- Database: Room
- Background Processing: WorkManager
- Email Library: Jakarta Mail
- Networking: Ktor Client
- Modern Kotlin-first HTTP client
- Coroutines support for efficient async operations
- Content negotiation with JSON serialization
- Plugin-based architecture for customization
- Logging capabilities for debugging
SmsReceiver
: BroadcastReceiver that captures incoming SMS messagesProcessSmsWorker
: WorkManager worker that processes messages in the backgroundSmsRepository
: Manages SMS message storage and retrievalFilterRuleRepository
: Manages filter rulesApiRepository
: Handles API communication using Ktor clientProcessNewSmsUseCase
: Orchestrates the SMS processing workflowApplyFilterUseCase
: Applies filter rules to SMS messagesSendEmailForSmsUseCase
: Handles email forwardingSendSmsToApiUseCase
: Handles API forwarding with Ktor client integration
The application uses Ktor Client for API communication with the following features:
- HttpClient Configuration: Custom setup with timeout settings and connection pooling
- JSON Serialization: Using kotlinx.serialization for efficient data transfer
- Authentication: Support for various authentication schemes
- Logging: Detailed request/response logging for debugging
- Error Handling: Comprehensive exception handling and retry mechanisms
- Request Building: Fluent API for constructing HTTP requests
- Response Processing: Type-safe response handling
This is a proof-of-concept application. It is not intended for production use in its current state. Features may be incomplete, and breaking changes might occur in future updates.
Feel free to use this codebase for learning and experimentation, but be aware of the following limitations:
- Security features are minimal
- Error handling may not cover all edge cases
- Performance optimizations are limited
- Documentation is still in progress
Contributions, suggestions, and feedback are welcome!
This project is protected under a NonCommercial License that restricts commercial use without explicit permission from the copyright holder. See the LICENSE file for details.
Key licensing terms:
- Free for personal, educational, and non-commercial use
- Commercial use requires prior written permission
- Contact information for commercial licensing is provided in the LICENSE file