Send SMS From Go Without a Twilio Account
To send an SMS from Go 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. Put the key in an environment variable; 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 net/http?
package smsnet
import (
"bytes"
"context"
"encoding/json"
"errors"
"net/http"
"os"
"time"
)
const baseURL = "https://smsnet.net/api/v1"
type Client struct {
http *http.Client
apiKey string
}
type SendRequest struct {
To string `json:"to"`
Body string `json:"body"`
Transactional bool `json:"transactional,omitempty"`
}
type Quota struct {
Month Monthly `json:"month"`
Day Daily `json:"day"`
}
type Monthly struct {
Used int `json:"used"`
Limit int `json:"limit"`
}
type Daily struct {
Used int `json:"used"`
Limit int `json:"limit"`
}
type SendResponse struct {
OK bool `json:"ok"`
MessageID string `json:"message_id"`
ConversationID string `json:"conversation_id"`
DeviceID string `json:"device_id"`
Quota Quota `json:"quota"`
}
func NewClient() (*Client, error) {
apiKey := os.Getenv("SMSNET_API_KEY")
if apiKey == "" {
return nil, errors.New("SMSNET_API_KEY not set")
}
return &Client{
http: &http.Client{Timeout: 15 * time.Second},
apiKey: apiKey,
}, nil
}
func (c *Client) Send(ctx context.Context, to, body string, transactional bool) (*SendResponse, error) {
reqBody := SendRequest{To: to, Body: body, Transactional: transactional}
jsonBody, err := json.Marshal(reqBody)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", baseURL+"/messages/send", bytes.NewReader(jsonBody))
if err != nil {
return nil, err
}
req.Header.Set("X-API-Key", c.apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := c.http.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
var errResp map[string]string
json.NewDecoder(resp.Body).Decode(&errResp)
return nil, errors.New("SMSNET " + resp.Status + ": " + errResp["error"])
}
var result SendResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, err
}
return &result, nil
}
Usage:
func main() {
client, err := smsnet.NewClient()
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
result, err := client.Send(ctx, "+15551234567", "Your table is ready. Reply STOP to opt out.", false)
if err != nil {
log.Fatal(err)
}
log.Printf("Message ID: %s, Day quota: %d/%d", result.MessageID, 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 Go?
Two options. Polling needs no public URL and suits a cron job; a webhook suits a server.
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.
type Message struct {
FromNumber string `json:"from_number"`
Body string `json:"body"`
ConversationID string `json:"conversation_id"`
}
type MessagePage struct {
Messages []Message `json:"messages"`
NextCursor string `json:"next_cursor"`
HasMore bool `json:"has_more"`
}
func (c *Client) PollInbound(ctx context.Context, since string) (*MessagePage, error) {
req, err := http.NewRequestWithContext(ctx, "GET", baseURL+"/messages", nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Set("direction", "inbound")
q.Set("limit", "100")
if since != "" {
q.Set("since", since)
}
req.URL.RawQuery = q.Encode()
req.Header.Set("X-API-Key", c.apiKey)
resp, err := c.http.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return nil, errors.New("poll failed: " + resp.Status)
}
var page MessagePage
if err := json.NewDecoder(resp.Body).Decode(&page); err != nil {
return nil, err
}
return &page, nil
}
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:
func WebhookHandler(secret string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
ts := r.Header.Get("X-SMSNET-Timestamp")
sig := r.Header.Get("X-SMSNET-Signature")
delivery := r.Header.Get("X-SMSNET-Delivery")
if ts == "" || sig == "" {
http.Error(w, "missing headers", http.StatusBadRequest)
return
}
if time.Since(time.Unix(parseInt64(ts), 0)) > 5*time.Minute {
http.Error(w, "timestamp expired", http.StatusBadRequest)
return
}
rawBody, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "read body", http.StatusBadRequest)
return
}
expected := "v1=" + hmacSHA256(secret, ts+"."+string(rawBody))
if !hmac.Equal([]byte(expected), []byte(sig)) {
http.Error(w, "invalid signature", http.StatusBadRequest)
return
}
// Dedupe on delivery ID (use Redis, DB, or in-memory map)
// if seen[delivery] { return }
// seen[delivery] = true
var event struct {
Event string `json:"event"`
Data json.RawMessage `json:"data"`
}
if err := json.Unmarshal(rawBody, &event); err != nil {
http.Error(w, "bad json", http.StatusBadRequest)
return
}
switch event.Event {
case "message.received":
var data struct {
From string `json:"from"`
Body string `json:"body"`
}
json.Unmarshal(event.Data, &data)
log.Printf("SMS from %s: %s", data.From, data.Body)
case "message.status":
var data struct {
MessageID string `json:"message_id"`
Status string `json:"status"`
}
json.Unmarshal(event.Data, &data)
log.Printf("Message %s is now %s", data.MessageID, data.Status)
}
w.WriteHeader(http.StatusOK)
}
}
func hmacSHA256(secret, data string) string {
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}
func parseInt64(s string) int64 {
i, _ := strconv.ParseInt(s, 10, 64)
return i
}
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?
| Status | When | What to do |
|---|---|---|
| 400 | Missing to or body, or no phone connected to the account | Fix the request, or connect a phone |
| 401 | Missing or wrong key; the error says whether the key was rotated | Load the key from the environment, rotate if needed |
| 403 | The recipient opted out; the error names the date and the words they used | Do not retry; remove them from your list |
| 429 | Monthly or daily allowance reached, including the headroom | Wait 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 Go 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 net/http with a typed client.
Do I need Twilio or a carrier account to send SMS from Go?
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 Go 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.
Related guides
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 C#, 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