Jemale Akil
Jemale Akil

Reputation: 21

Error sending SMS with Golang SMPP protocol: Unknown address

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

Upvotes: 2

Views: 420

Answers (1)

Jemale Akil
Jemale Akil

Reputation: 21

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())
}

Upvotes: 0

Related Questions