Send SMS with C# from your own phone.
To send an SMS from C#, POST a number and a message to https://app.sms8.io/api/v1/messages with HttpClient and your API key in the X-Api-Key header. No NuGet package is needed. The text leaves from the SIM in your own Android phone, with no per-message fee and no A2P 10DLC filing.
Quick start in three steps
From a new account to a delivered text in a few minutes.
Get your API key
Create an SMS8 account, pair an Android phone with the SMS8 app, and copy your key from the API page of the dashboard. Store it in an environment variable or user secret called SMS8_API_KEY.
Use HttpClient
Everything below uses HttpClient and System.Text.Json from the base library. Prefer a class? The dashboard API page offers a ready C# class with async methods.
Send your first SMS
Run the snippet with your own number. The phone you paired sends the text from its SIM, and you get a message ID back.
How do I send an SMS with C#?
The API takes a form post and answers in JSON. Reuse one HttpClient for the life of your app.
using System.Text.Json;
var http = new HttpClient { BaseAddress = new Uri("https://app.sms8.io/api/v1/") };
http.DefaultRequestHeaders.Add("X-Api-Key", Environment.GetEnvironmentVariable("SMS8_API_KEY"));
async Task<JsonElement> Sms8Post(string path, Dictionary<string, string> fields)
{
using var resp = await http.PostAsync(path, new FormUrlEncodedContent(fields));
using var doc = JsonDocument.Parse(await resp.Content.ReadAsStringAsync());
return doc.RootElement.Clone();
}
var res = await Sms8Post("messages", new()
{
["number"] = "+14155550100",
["message"] = "Hello from C# and SMS8",
});
if (res.GetProperty("success").GetBoolean())
{
var id = res.GetProperty("data").GetProperty("messages")[0].GetProperty("ID");
Console.WriteLine($"queued as {id}");
}
else
{
var err = res.GetProperty("error");
Console.WriteLine($"refused: {err.GetProperty("code")} {err.GetProperty("message")}");
}
Every answer has the same shape: success, data and an error object with a code and a message. Always read the flag, because some refusals, such as no credits left, come back inside a normal response. In ASP.NET Core, register the client with IHttpClientFactory instead of creating it by hand.
How do I send SMS to many numbers in C#?
For the same text, join the numbers with commas in number. Add option 1 to rotate across every phone you paired, or 2 to rotate across every SIM.
string[] numbers = { "+14155550100", "+14155550101", "+14155550102" };
var bulk = await Sms8Post("messages", new()
{
["number"] = string.Join(",", numbers),
["message"] = "The store opens at 9:00 tomorrow.",
["option"] = "1",
});
For a different text per person, send a messages field holding a JSON list:
var batch = new[]
{
new { number = "+14155550100", message = "Hi Ana, your table for 4 is ready." },
new { number = "+14155550101", message = "Hi Ben, your order #4412 has shipped." },
};
await Sms8Post("messages", new() { ["messages"] = JsonSerializer.Serialize(batch) });
Add schedule with a Unix timestamp, such as DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeSeconds().ToString(), to send later, and prioritize set to 1 for codes and alerts. The API has no artificial rate limit, but each SIM should send about one message every 10 to 30 seconds; add phones to send more.
How do I send an MMS with C#?
Set type to mms and put public image links in attachments, separated by commas. JPG, PNG, GIF and WEBP work, and SMS8 resizes each image to 1,280 pixels.
await Sms8Post("messages", new()
{
["number"] = "+14155550100",
["message"] = "Here is your receipt.",
["type"] = "mms",
["attachments"] = "https://example.com/receipt.jpg,https://example.com/map.png",
});
More in the guide on sending MMS through an API.
How do I read SMS replies in C#?
Poll for messages received in the last hour
var since = DateTimeOffset.UtcNow.AddHours(-1).ToUnixTimeSeconds().ToString();
var read = await Sms8Post("messages/read", new()
{
["status"] = "Received",
["startTimestamp"] = since,
["limit"] = "100",
});
if (read.GetProperty("success").GetBoolean())
{
foreach (var m in read.GetProperty("data").GetProperty("messages").EnumerateArray())
Console.WriteLine($"{m.GetProperty("number")}: {m.GetProperty("message")}");
}
When nothing matches, the answer is success: false with error code 404. Treat that as an empty list. You can also filter by id, deviceID, simSlot or endTimestamp, and page with limit and offset.
Receive replies with a signed webhook (ASP.NET Core)
Add an HTTPS URL on the Webhooks page of the dashboard and subscribe it to received messages. Each request carries an X-Signature header: sha256= followed by the hex HMAC-SHA256 of the raw body, keyed with that webhook's own signing secret (not your API key).
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var secret = Encoding.UTF8.GetBytes(builder.Configuration["SMS8_WEBHOOK_SECRET"]!);
app.MapPost("/sms8/webhook", async (HttpRequest req) =>
{
using var ms = new MemoryStream();
await req.Body.CopyToAsync(ms);
var raw = ms.ToArray();
var expected = "sha256=" + Convert.ToHexString(HMACSHA256.HashData(secret, raw)).ToLowerInvariant();
var received = req.Headers["X-Signature"].ToString();
if (!CryptographicOperations.FixedTimeEquals(
Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(received)))
return Results.Unauthorized();
using var doc = JsonDocument.Parse(raw);
if (doc.RootElement.TryGetProperty("data", out var data) && data.ValueKind == JsonValueKind.Array)
foreach (var m in data.EnumerateArray())
SaveReply(m.GetProperty("ID").ToString(), m.GetProperty("number").GetString(),
m.GetProperty("message").GetString()); // your code: dedupe on ID
return Results.Ok();
});
app.Run();
A received message arrives with event, timestamp, userID and a data list where each item has ID, number, message, deviceID and simSlot. Answer within 10 seconds and queue slow work. If your server is down, SMS8 retries on a growing schedule for up to 30 days. The trade-offs are in webhook vs polling for incoming SMS.
Errors and retries
| What you see | Meaning | What to do |
|---|---|---|
| Error code 401 | Missing or wrong API key | Fix the key. Do not retry |
| Error code 400 | Missing or malformed fields | Fix the request. Do not retry |
success: false with a message | Refused, for example no credits left | Log and alert. Retrying will not help |
| Error code 404 on a read | No messages match | Treat as an empty list |
| Error code 500, HTTP 5xx or a timeout | Temporary problem | Retry with backoff |
Retry only on timeouts and server errors, and pass an idempotencyKey so a retry never becomes a second text. SMS8 also returns the first answer for an identical request repeated within five minutes.
async Task<JsonElement> SendWithRetry(string number, string text, string key, int attempts = 4)
{
for (var i = 0; i < attempts; i++)
{
try
{
var res = await Sms8Post("messages", new()
{
["number"] = number, ["message"] = text, ["idempotencyKey"] = key,
});
if (res.GetProperty("success").GetBoolean())
return res.GetProperty("data").GetProperty("messages")[0];
var err = res.GetProperty("error");
if (err.GetProperty("code").GetInt32() != 500)
throw new InvalidOperationException(err.GetProperty("message").GetString()); // 400, 401, no credits
}
catch (HttpRequestException) { } // network error: retry
catch (TaskCanceledException) { } // timeout: retry
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, i))); // 1s, 2s, 4s, 8s
}
throw new Exception("SMS8 send failed after retries");
}
If the phone later reports a message as failed, put the original back in the queue with messages/resend and its id, instead of sending a new copy. Every field is in the SMS8 API documentation, and the SMS API guide for developers covers pacing and bulk sends in depth.
Why choose SMS8 for .NET
An SMS API without a number to rent or a meter to watch.
Your own number
Texts leave from the SIM in your own Android phone, so customers see a number they know and can reply to it.
Flat price, unlimited messages
USD 29 a month for one phone, USD 89 for five and USD 229 for twenty, with unlimited SMS and MMS and no per-message fee. Yearly billing is half the price.
No A2P 10DLC filing
Texts go person-to-person from your SIM, so there is no brand or campaign registration to wait for.
Runs on every .NET
Plain HttpClient works in ASP.NET Core, worker services and console apps. The ready C# class targets modern .NET, .NET Framework 4.6.2 and newer, Unity, Xamarin and MAUI.
Signed webhooks with long retries
Replies arrive at your server signed with HMAC-SHA256 and are retried for up to 30 days if your server is down.
Setup in minutes, with a trial
Pair a phone, copy a key and send. The 3-day trial includes 30 messages and needs no card.
Keep going
The reference, the guides and the same examples in other languages.
SMS8 API documentation
Every endpoint, field and webhook event in one place.
Open the docsSMS API guide for developers
Sending, receiving, signatures, retries and pacing, with code in four languages.
Read the guideWebhook vs polling
Which way to receive incoming SMS, and a clean polling loop when you need one.
Read the articleSend SMS with Python
requests and a Flask webhook.
Python examplesSend SMS with Node.js
The sms8-sdk package from npm, plus plain fetch.
Node.js examplesSend SMS with PHP
curl, hash_hmac and a ready PHP class.
PHP examplesSend SMS with curl
Test every endpoint from the terminal.
curl examplesYou do not need one. HttpClient and a form post are the whole integration. The API page of your dashboard also offers a ready C# class with async methods you can drop into your project.
Register an HttpClient with IHttpClientFactory, set the X-Api-Key header, and post number and message as FormUrlEncodedContent to https://app.sms8.io/api/v1/messages. Read the success flag in the JSON answer.
Start the SMS8 trial: 3 days and 30 messages with no card. After that, a flat plan from USD 29 a month covers unlimited SMS and MMS from your own phone.
Compute sha256= plus the lowercase hex HMACSHA256 of the raw request body with your webhook signing secret, and compare it to the X-Signature header with CryptographicOperations.FixedTimeEquals.
The API has no artificial limit. Each SIM should send about one message every 10 to 30 seconds, so add phones and set option to 1 or 2 to rotate across them.
Send your first SMS from C#
Pair a phone, copy your API key and run the snippet. 3-day trial with 30 messages, no card needed.