Home › Send SMS with C# (.NET)
Send SMS with C# (.NET)
Send an SMS to a UK mobile from C# with one HTTPS request to the Bremlio API. Real, runnable code — authentication, request, response and error handling — at 4.65p per message, pay as you go.
Get your API key free1. Setup & authentication
Uses HttpClient from .NET. Read the API key from an environment variable. Create an API key in the Bremlio dashboard and
authenticate by sending it in the X-Api-Key header. Numbers can be UK national
(07…) or E.164 (+44…).
2. Send an SMS in C#
using System.Net.Http;
using System.Text;
using var http = new HttpClient();
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.bremlio.com/v1/messages");
req.Headers.Add("X-Api-Key", Environment.GetEnvironmentVariable("BREMLIO_API_KEY"));
req.Content = new StringContent(
"{\"to\":\"+447700900123\",\"message\":\"Your order has been confirmed.\"}",
Encoding.UTF8, "application/json");
var resp = await http.SendAsync(req);
var body = await resp.Content.ReadAsStringAsync();
Console.WriteLine(resp.IsSuccessStatusCode ? $"accepted: {body}" : $"failed: {(int)resp.StatusCode} {body}");
3. The response
{
"success": true,
"message_id": "a1b2c3d4-…",
"provider_message_id": "…",
"status": "accepted",
"credits_remaining": 24
}
4. Errors to handle
The API returns a JSON {"error": "..."} with an appropriate HTTP status. Common cases:
| Status | Meaning |
|---|---|
| 400 | Invalid request — e.g. missing/!UK number, or empty/too-long message. |
| 401 | Invalid or missing API key. |
| 402 | Insufficient credits — top up to continue. |
| 403 | Account pending verification, recipient suppressed, or blocked by content policy. |
5. Production tips
- Keep the API key in an environment variable or secret store — never in source or client-side code.
- Check
status == "accepted"and store themessage_idto reconcile delivery later. - Handle non-2xx responses and retry transient network errors with backoff (the send itself is a single request).
- Validate/normalise numbers to +44 before sending to avoid 400s.
Frequently asked questions
- How do I send an SMS with C#?
- Make an HTTPS POST to https://api.bremlio.com/v1/messages with your API key in the X-Api-Key header and a JSON body of {"to", "message"}. The full C# example is above.
- What do I need to start?
- A Bremlio account and an API key (created in the dashboard). New accounts get 25 free credits, so you can run the example end to end before paying.
- How much does it cost?
- 4.65p per SMS to a UK mobile, pay as you go, no monthly fee.
- How do I check delivery?
- The send response returns a message_id and status. Delivery status is then available in the dashboard and via the message-history API.
Send your first SMS from C# today.
Get your API key freeRelated
SMS API · UK SMS API · OTP API · Full developer docs · Pricing