SMSNET
Guide

Send SMS From C# Without a Twilio Account

To send an SMS from C# you make one authenticated HTTP request. With SMSNET that request makes your own Android phone send the text, so there is no provider account and no number to rent.

What do I need before the first call?

Two things: a connected phone and an API key. Install the SMSNET Gateway app on any Android 8.0 or newer phone with a SIM, sign in, and the last screen of setup shows your key once. The Android gateway guide shows every screen. Store the key in user secrets, environment variables, or Azure Key Vault; it can be rotated from the Developers page if it ever leaks.

The free plan is enough to build against: 300 messages a month, 20 a day, and replies are never counted. Recipients go in E.164 format (+15551234567), and the person you are texting should have agreed to hear from you.

How do I send an SMS with HttpClient (.NET 8)?

Create a typed HttpClient with the base address and default headers:

// SmsClient.cs
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;

public class SmsClient
{
    private readonly HttpClient _http;
    private readonly string _apiKey;

    public SmsClient(HttpClient http, IConfiguration config)
    {
        _http = http;
        _apiKey = config["SmsNet:ApiKey"] ?? Environment.GetEnvironmentVariable("SMSNET_API_KEY")
            ?? throw new InvalidOperationException("SMSNET_API_KEY not configured");
        
        _http.BaseAddress = new Uri("https://smsnet.net/api/v1/");
        _http.DefaultRequestHeaders.Add("X-API-Key", _apiKey);
        _http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    }

    public record SendRequest(string To, string Body, bool Transactional = false);
    public record Quota(Monthly Month, Daily Day);
    public record Monthly(long Used, long Limit);
    public record Daily(long Used, long Limit);
    public record SendResponse(bool Ok, string MessageId, string ConversationId, string DeviceId, Quota Quota);

    public async Task<SendResponse> SendAsync(string to, string body, bool transactional = false, CancellationToken ct = default)
    {
        var request = new SendRequest(to, body, transactional);
        var response = await _http.PostAsJsonAsync("messages/send", request, ct);
        
        if (!response.IsSuccessStatusCode)
        {
            var error = await response.Content.ReadAsStringAsync(ct);
            throw new HttpRequestException($"SMSNET {(int)response.StatusCode}: {error}");
        }
        
        return await response.Content.ReadFromJsonAsync<SendResponse>(cancellationToken: ct)
            ?? throw new InvalidOperationException("Empty response from SMSNET");
    }
}

Register in Program.cs (ASP.NET Core):

builder.Services.AddHttpClient<SmsClient>(client =>
{
    client.Timeout = TimeSpan.FromSeconds(15);
});

Or for a console app:

var client = new HttpClient { BaseAddress = new Uri("https://smsnet.net/api/v1/") };
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);

Send a message:

var result = await _smsClient.SendAsync("+15551234567", "Your table is ready. Reply STOP to opt out.");
Console.WriteLine($"Message ID: {result.MessageId}, Quota: {result.Quota.Day.Used}/{result.Quota.Day.Limit}");

A successful response looks like this:

{
  "ok": true,
  "message_id": "msg_01j9x8k2...",
  "conversation_id": "conv_01j9x8k2...",
  "device_id": "dev_01j9x8k2...",
  "quota": {
    "month": { "used": 13, "limit": 300 },
    "day": { "used": 4, "limit": 20 }
  }
}

quota is there so your app can slow down before it hits the wall instead of discovering it as a 429. The limit has a fifth of headroom above it; once you are in that band the response carries "grace": true and a note.

Set transactional = true only for a message the recipient is waiting on right now, such as a login code. It skips the queue's pacing gap and quiet hours and reaches the phone in about a second, while still respecting the daily ceiling and the warmup ramp on a new line.

How do I read replies in C#?

Two options. Polling needs no public URL and suits a background service; a webhook suits a web app.

Polling uses the message feed with a cursor. The first call without since returns the latest messages; every call after that passes back next_cursor, so nothing is missed or repeated even when several messages share a millisecond.

public record Message(string FromNumber, string Body, string ConversationId);
public record MessagePage(List<Message> Messages, string NextCursor, bool HasMore);

public async Task<MessagePage> PollInboundAsync(string since = null, CancellationToken ct = default)
{
    var query = new Dictionary<string, string?>
    {
        ["direction"] = "inbound",
        ["limit"] = "100",
        ["since"] = since
    };
    var uri = QueryHelpers.AddQueryString("/messages", query);
    return await _http.GetFromJsonAsync<MessagePage>(uri, ct)
        ?? throw new InvalidOperationException("Empty response");
}

For a webhook, register your HTTPS endpoint once (PUT /api/v1/webhooks with {"url": "..."}) and keep the secret from the response. SMSNET then POSTs message.received and message.status events, signs each one, and retries nine times over about three days if your endpoint is down. Verify the signature before trusting anything:

[ApiController]
[Route("sms/webhook")]
public class SmsWebhookController : ControllerBase
{
    private readonly string _secret;
    private readonly ILogger<SmsWebhookController> _log;

    public SmsWebhookController(IConfiguration config, ILogger<SmsWebhookController> log)
    {
        _secret = config["SmsNet:WebhookSecret"] ?? Environment.GetEnvironmentVariable("SMSNET_WEBHOOK_SECRET")
            ?? throw new InvalidOperationException("SMSNET_WEBHOOK_SECRET not configured");
        _log = log;
    }

    [HttpPost]
    public async Task<IActionResult> Receive(
        [FromHeader(Name = "X-SMSNET-Timestamp")] string timestamp,
        [FromHeader(Name = "X-SMSNET-Signature")] string signature,
        [FromHeader(Name = "X-SMSNET-Delivery")] string deliveryId)
    {
        if (string.IsNullOrEmpty(timestamp) || string.IsNullOrEmpty(signature))
            return BadRequest("Missing headers");

        if (Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - long.Parse(timestamp)) > 300)
            return BadRequest("Timestamp out of 5-minute window");

        // Read raw body for signature verification
        Request.EnableBuffering();
        using var reader = new StreamReader(Request.Body, Encoding.UTF8, leaveOpen: true);
        var rawBody = await reader.ReadToEndAsync();
        Request.Body.Position = 0;

        var expected = "v1=" + ComputeHmacSha256(_secret, timestamp + "." + rawBody);
        if (!CryptographicOperations.FixedTimeEquals(
            Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(signature)))
            return BadRequest("Invalid signature");

        // Dedupe on deliveryId (store in Redis, DB, or in-memory for demo)
        // if (await _dedupeStore.ExistsAsync(deliveryId)) return Ok();
        // await _dedupeStore.AddAsync(deliveryId);

        var eventObj = JsonSerializer.Deserialize<JsonElement>(rawBody);
        var eventType = eventObj.GetProperty("event").GetString();

        if (eventType == "message.received")
        {
            var from = eventObj.GetProperty("data").GetProperty("from").GetString();
            var body = eventObj.GetProperty("data").GetProperty("body").GetString();
            _log.LogInformation("SMS from {From}: {Body}", from, body);
        }
        else if (eventType == "message.status")
        {
            var msgId = eventObj.GetProperty("data").GetProperty("message_id").GetString();
            var status = eventObj.GetProperty("data").GetProperty("status").GetString();
            _log.LogInformation("Message {MessageId} is now {Status}", msgId, status);
        }

        return Ok();
    }

    private static string ComputeHmacSha256(string secret, string data)
    {
        using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
        var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(data));
        return Convert.ToHexString(hash).ToLowerInvariant();
    }
}

The signed material is the timestamp, a dot, and the raw request body, so verify against the raw body before anything parses it. Dedupe on the X-SMSNET-Delivery header, which is stable across retries. Send yourself a test event with POST /api/v1/webhooks/test before any real traffic exists.

What errors should the script expect?

StatusWhenWhat to do
400Missing to or body, or no phone connected to the accountFix the request, or connect a phone
401Missing or wrong key; the error says whether the key was rotatedLoad the key from configuration, rotate if needed
403The recipient opted out; the error names the date and the words they usedDo not retry; remove them from your list
429Monthly or daily allowance reached, including the headroomWait for the window, or upgrade the plan

Everything in this guide runs on the free plan. For the full endpoint list, including conversations, contacts and campaigns, see What Is an SMS API and How to Use One. If you would rather have an AI agent do the calling, the MCP server guide exposes the same operations as tools.

FAQ

How do I send an SMS from a C# application?

POST JSON with to and body to https://smsnet.net/api/v1/messages/send, with your SMSNET API key in the X-API-Key header. The response returns a message_id and your remaining quota, and the message is sent from the Android phone connected to your account. Use HttpClient with PostAsJsonAsync in .NET 8.

Do I need Twilio or a carrier account to send SMS from C#?

No. SMSNET uses an Android phone and SIM you already own as the sender, so there is no carrier account and no number rental; you text from your own number on your own plan. The free plan covers 300 messages a month and replies are never counted.

How do I know the SMS was delivered?

Either poll GET /api/v1/messages and read each message's status, or register a webhook and receive a message.status event when the message reaches sent, delivered or failed. Delivery confirmation comes from the recipient's handset via the carrier, so timing varies by network.

Can my C# application receive SMS replies?

Yes. Poll GET /api/v1/messages?direction=inbound with the next_cursor from the previous call, or register an HTTPS webhook and receive message.received events signed with HMAC-SHA256 over the timestamp and raw body.

How fast does the message arrive?

An ordinary message is paced and usually leaves within a minute or two, subject to civil hours where the recipient is. A message marked transactional = true is handed to the phone immediately and typically reaches the handset in about a second. New lines are limited to 100 messages a day until they have warmed up.

What phone number does the recipient see?

The number of the SIM in your connected Android phone. It is your own number, so replies come straight back to you and the conversation stays in one thread.

This is a spoke of What Is an SMS API and How to Use One. Siblings: Send an SMS from Node.js, Send an SMS from Python, Send SMS From PHP, Send SMS From Java, Send SMS From Go, Send SMS From Ruby. The phone comes from Turn Your Android Phone into an SMS Gateway; the agent route is What Is an MCP Server for SMS?.

Send your first message today

Free plan, no card: 400 messages a month from your own number, with the API, webhooks and MCP included.

Get the app See pricing

Get it on Google Play

Written by , who builds SMSNET. Product facts on this page are checked against the live pricing page and the running API on the date shown above.