| Crates.io | smsir-rust |
| lib.rs | smsir-rust |
| version | 0.1.0 |
| created_at | 2025-08-08 14:33:33.178056+00 |
| updated_at | 2025-08-08 14:33:33.178056+00 |
| description | A fast, secure, and modular Rust library for interacting with the SMS.ir SMS API, with built-in error handling and a clean, idiomatic interface. |
| homepage | https://github.com/rustsi/smsir-rust |
| repository | https://github.com/rustsi/smsir-rust |
| max_upload_size | |
| id | 1786849 |
| size | 85,355 |
smsir-rust is a secure and fast library for communicating with the SMS.ir SMS web service in the Rust programming language. This library is developed with modular design and error handling in mind.
cargo add smsir-rust
Or manually add the following to the [dependencies] section of your Cargo.toml file:
smsir-rust = "0.1.0"
Then:
cargo build
First, obtain your API key from the SMS.ir panel and use it in your code.
use smsir_rust::service::SmsService;
let api_key = "YOUR_API_KEY";
let service = SmsService::new(api_key);
let result = service.send_single(
"Sender number",
"Message text",
"Receiver number"
);
match result {
Ok(response) => println!("Sent successfully: {:?}", response),
Err(e) => eprintln!("Error: {}", e),
}
let mobiles = vec!["09123456789", "09121234567"];
let result = service.send_bulk(
"Sender number",
"Message text",
&mobiles,
None // For immediate sending
);
let params = vec![("Code", "12345")];
let result = service.send_verify(
"Receiver number",
100000, // Template ID
¶ms
);
let credit = service.get_credit();
let lines = service.get_lines();
service: Main API interaction methodsresult: Response data structureserror: Error handlingTo run integration tests and ensure the library functions properly, you need to set a few environment variables with real values. These variables are required for different tests related to sending SMS and receiving reports:
SMSIR_API_KEY: API key from the SMS.ir panelSMSIR_TEST_MOBILE: Valid mobile number for testing (e.g. 09123456789)SMSIR_TEST_SENDER: Active sender number from your panel (e.g. 3000...)SMSIR_TEST_TEMPLATE_ID: Template ID for OTP message (e.g. 123456)SMSIR_TEST_PACK_ID: A valid pack_id for testing scheduled message deletionSMSIR_TEST_MSG_ID: A valid msg_id for testing message reportNote: If any of these variables is not set, the corresponding test will not run and an appropriate message will be shown.
cargo test --test integration
If the tests pass successfully, you will see output like the following:
running 8 tests
test integration::test_get_credit ... ok
test integration::test_bulk_send ... ok
...
test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
If an error occurs, an error message will be displayed. Please make sure all environment variables are set with valid values and you are connected to the internet.