Error sending SMS with Golang SMPP protocol: Unknown address

200 views Asked by At

I'm using the Golang SMPP protocol to send SMS messages. The messages are being sent successfully, but the source address displayed on the recipient's phone is "Unknown address".

Here is my code -- main.go

package main

import (
    "log"

    "github.com/fiorix/go-smpp/smpp"
    "github.com/fiorix/go-smpp/smpp/pdu/pdufield"
    "github.com/fiorix/go-smpp/smpp/pdu/pdutext"
)

func main() {
    tx := &smpp.Transmitter{
        Addr:   "server:port",
        User:   "userId",
        Passwd: "password",
    }
    // Create persistent connection, wait for the first status.
    conn := <-tx.Bind()
    if conn.Status() != smpp.Connected {
        log.Fatal(conn.Error())
    }
    sm, err := tx.Submit(&smpp.ShortMessage{
        Src:      "MyCompany",
        Dst:      "25*********",
        Text:     pdutext.Raw("Sample sms"),
        Register: pdufield.NoDeliveryReceipt,
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Message ID:", sm.RespID())
}

-- go.mod

module sms

go 1.21.0

require github.com/fiorix/go-smpp v0.0.0-20210403173735-2894b96e70ba

require golang.org/x/text v0.3.6 // indirect

Image Example I followed: https://pkg.go.dev/github.com/fiorix/go-smpp/smpp#example-Transmitter

2

There are 2 answers

2
Jeevan ebi On

According to SMPP specifications, the source address (often referred to as the "sender ID") can be up to 11 alphanumeric characters. The string "MyCompany" in your example is longer than the allowed length, which might be causing the issue.

Try using a shorter alphanumeric string for the source address:

sm, err := tx.Submit(&smpp.ShortMessage{
    Src:      "MyCo",
    Dst:      "25*********",
    Text:     pdutext.Raw("Sample sms"),
    Register: pdufield.NoDeliveryReceipt,
})
0
Jemale Akil On

I've spent a considerable amount of time searching the solution for this. I found a hint for the solution from another go-smpp library on this link https://melroselabs.com/docs/tutorials/sms/send-sms-with-smpp-using-go/. I just added: SourceAddrTON: 5 and SourceAddrNPI: 0 and now it works! [displaying MyCompany on the sms src]. Here is the full working code.

package main

import (
    "log"

    "github.com/fiorix/go-smpp/smpp"
    "github.com/fiorix/go-smpp/smpp/pdu/pdufield"
    "github.com/fiorix/go-smpp/smpp/pdu/pdutext"
)

func main() {
    tx := &smpp.Transmitter{
        Addr:   "server:port",
        User:   "userId",
        Passwd: "password",
    }
    // Create persistent connection, wait for the first status.
    conn := <-tx.Bind()
    if conn.Status() != smpp.Connected {
        log.Fatal(conn.Error())
    }
    sm, err := tx.Submit(&smpp.ShortMessage{
        Src:      "MyCompany",
        Dst:      "25*********",
        Text:     pdutext.Raw("Sample sms"),
        Register: pdufield.NoDeliveryReceipt,
        // **ADDED THESS 2 FIELDS**
        SourceAddrTON: 5,
        SourceAddrNPI: 0,
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Message ID:", sm.RespID())
}