Send SMS from C#
This guide shows how to send a text message from C# with the NS SMS API. The SMS goes out from your own Android phone and SIM card, so there is no per-message fee and no sender registration. You need about five minutes.
Before you start
- An Android phone (8.0 or newer) with a SIM card that can send SMS.
- The NS SMS app from Google Play, set as the default SMS app, with the API turned on.
- Your phone ID and API key from the API tab. Store them as the environment variables NS_SMS_DEVICE_ID and NS_SMS_API_KEY.
No account, email or password. The phone registers itself and shows your API key in the app.
Step 1: send an SMS from C#
POST the recipient in international format (E.164, for example +14155550123) and the text. The API answers 202 Accepted with the message ID.
using System.Net.Http.Headers;
using System.Net.Http.Json;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("NS_SMS_API_KEY"));
var response = await http.PostAsJsonAsync("https://sms-api.n-soft.pl/v1/sms/send", new
{
device_id = Environment.GetEnvironmentVariable("NS_SMS_DEVICE_ID"),
to = "+14155550123",
text = "Your code is 4821",
});
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
Step 2: check the delivery status
GET /v1/sms/{id} returns the current status: received by the phone, sent, delivered or failed with an error code. Statuses usually change within seconds.
GET https://sms-api.n-soft.pl/v1/sms/01JDX4K8Q2M3N4P5R6S7T8V9W0
Authorization: Bearer $NS_SMS_API_KEY
{"id":"01JDX4K8Q2M3N4P5R6S7T8V9W0","status":"delivered","error_code":null,
"sent_at":"2026-11-26T10:58:30+00:00","delivered_at":"2026-11-26T10:58:31+00:00", ...}
Step 3: receive status webhooks (optional)
On every plan the server POSTs every status change to your webhook. Check the signature before you trust the request:
using System.Security.Cryptography;
using System.Text;
var app = WebApplication.Create(args);
app.MapPost("/sms-status", async (HttpRequest request) =>
{
using var reader = new StreamReader(request.Body);
var body = await reader.ReadToEndAsync();
var key = Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("NS_SMS_WEBHOOK_SECRET")!);
var expected = "sha256=" + Convert.ToHexString(HMACSHA256.HashData(key, Encoding.UTF8.GetBytes(body))).ToLowerInvariant();
var given = request.Headers["X-Signature"].ToString();
if (!CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(given)))
return Results.Unauthorized();
Console.WriteLine(body);
return Results.NoContent();
});
app.Run();
Step 4: schedule an SMS for later
Add send_at to the same request to send at a set time, and repeat for daily, weekly or monthly texts:
{
"device_id": "01JDX4K8Q2M3N4P5R6S7T8V9W0",
"to": "+14155550123",
"text": "Reminder: your appointment is tomorrow at 10:00",
"send_at": "2026-12-01T09:00:00+01:00",
"repeat": { "every": "weekly", "count": 4 }
}