RSS Feed for This PostCurrent Article

Bulk SMS Gateway using the Open Source .NET SMS Library

The SMS library has a new website at https://twit88.com/platform/projects/show/messagingtoolkit

Download Source Code

I reposted here an article that I posted before in CodeProject as there are someone requested for it.

Introduction

According to pmi-fr.org Short Message Service (SMS) is becoming a popular way of marketing nowadays. Normally in order to send bulk SMS, we need to rely on the telco operators or any third party service providers to provide the bulk SMS sending facility. If you are looking for new online marketing strategies, check out Chatmeter to learn more In this article, I am going to show you how to make use of your mobile phone or a GSM modem attached to your computer to send bulk SMS using the open source atSMS library and a open source bulk SMS gateway that I have developed.

smsgateway.jpg

Open Source .NET SMS Library

I have developed a open source phone communication library that can be used to send or receive SMS. It is simple to send bulk SMS using the library.

Code snippet for bulk SMS sending is shown here.

Imports ATSMS
Imports ATSMS.SMS
Public Class MainForm
Private Const PHONE_BOOK As String = “phonebook.txt”

Private m_strPhoneBook As String
Private WithEvents oGsmModem As New GSMModem
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnConnect.Click

If cboComPort.Text = String.Empty Then
MsgBox(“COM Port must be selected”, MsgBoxStyle.Information)
Return
End If

oGsmModem.Port = cboComPort.Text
If cboBaudRate.Text <> String.Empty Then
oGsmModem.BaudRate = Convert.ToInt32(cboBaudRate.Text)
End If

If cboDataBit.Text <> String.Empty Then
oGsmModem.DataBits = Convert.ToInt32(cboDataBit.Text)
End If

If cboStopBit.Text <> String.Empty Then

Select Case cboStopBit.Text

Case “1”

oGsmModem.StopBits = Common.EnumStopBits.One

Case “1.5”

oGsmModem.StopBits = Common.EnumStopBits.OnePointFive

Case “2”

oGsmModem.StopBits = Common.EnumStopBits.Two

End Select

End If

If cboFlowControl.Text <> String.Empty Then

Select Case cboFlowControl.Text

Case “None”

oGsmModem.FlowControl = Common.EnumFlowControl.None

Case “Hardware”

oGsmModem.FlowControl = Common.EnumFlowControl.RTS_CTS

Case “Xon/Xoff”

oGsmModem.FlowControl = Common.EnumFlowControl.Xon_Xoff

End Select

End If

Try

oGsmModem.Connect()

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical)

Return

End Try

Try

oGsmModem.NewMessageIndication = True

Catch ex As Exception

End Try

btnSend.Enabled = True

btnDisconnect.Enabled = True

btnConnect.Enabled = False

oGsmModem.AutoDeleteSentMessage = True

MsgBox(“Connected to phone successfully !”, MsgBoxStyle.Information)

End Sub

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

CheckForIllegalCrossThreadCalls = False

Initialize()

End Sub

Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click

Try

oGsmModem.Disconnect()

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical)

End Try

btnSend.Enabled = False

btnDisconnect.Enabled = False

btnConnect.Enabled = True

End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Dim msisdn As String = InputBox(“Enter a valid phone number”, “Bulk SMS Gateway”)

If msisdn <> String.Empty Then

lstPhoneList.Items.Add(msisdn)

SavePhoneBook()

End If

End Sub

Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click

lstPhoneList.Items.Remove(lstPhoneList.SelectedItem)

SavePhoneBook()

End Sub

Private Sub Initialize()

‘ Read from the phone book

Dim strContent As String

m_strPhoneBook = Application.StartupPath & “\” & PHONE_BOOK

If My.Computer.FileSystem.FileExists(m_strPhoneBook) Then

strContent = My.Computer.FileSystem.ReadAllText(m_strPhoneBook)

Dim lines() As String = strContent.Split(ControlChars.CrLf)

Dim i As Integer

For i = 0 To lines.Length – 1

lstPhoneList.Items.Add(lines(i))

Next

End If

End Sub

Private Sub SavePhoneBook()

Dim strFileContent As String = String.Empty

For Each item As String In lstPhoneList.Items

strFileContent += item & ControlChars.CrLf

Next

My.Computer.FileSystem.WriteAllText(m_strPhoneBook, strFileContent, False)

‘MsgBox(“Saved !”, MsgBoxStyle.Information)

End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

If txtMsg.Text.Trim = String.Empty Then

MsgBox(“Message must not be empty !”, MsgBoxStyle.Information)

Return

End If

If StringUtils.IsUnicode(txtMsg.Text) Then

oGsmModem.Encoding = Common.EnumEncoding.Unicode_16Bit

Else

oGsmModem.Encoding = Common.EnumEncoding.GSM_Default_7Bit

End If

For Each item As String In lstPhoneList.Items

If item.Trim <> String.Empty Then

oGsmModem.SendSMSToOutbox(item.Trim, txtMsg.Text.Trim)

End If

Next

MsgBox(“Message is queued for sending !”, MsgBoxStyle.Information)

End Sub

Private Sub oGsmModem_OutboxSMSSent(ByVal e As ATSMS.OutboxSMSSentEventArgs) Handles oGsmModem.OutboxSMSSent

If e.ErrorCode > 0 Then

txtMsgDeliveryStatus.Text += “Error sending message to ” & e.DestinationNumber & “. ” & e.ErrorDescription & ControlChars.CrLf

Else

txtMsgDeliveryStatus.Text += “Message is delivered to ” & e.DestinationNumber & ControlChars.CrLf

End If

End Sub

End Class

The Code

The phone numbers are stored in a text file. When you click the Send button, the message will be sent to the message outbox which will be handled by a separate thread in the library. When the message is sent for each phone number, message sent event is raised.

AutoDeleteSentMessage is set to true as we do not want to sent message to occupy the phone storage. If the storage is full, you may not able to send any more messages.


Trackback URL


RSS Feed for This Post33 Comment(s)

  1. Farukh Gee | Oct 5, 2008 | Reply

    (Sameer) this is very generic error, please debug to reach the line of error. or see complete details of error to get line or source of error.

  2. Vivek | Oct 9, 2008 | Reply

    The software shows CANNOT SEND SMS: MEMORY FULL when I have 25 messages in my inbox.

    Is there any way to delete the messages in the inbox ?

  3. Malhar Shah | Oct 20, 2008 | Reply

    as per my requirement i want to send 20000 sms in 1 sec…
    is this possible…?
    if yes then please giveme solution…
    and if it is not possible then please give me other alterbnative….

    Thanks in Advance…
    Malhar Shah

  4. abiola | Nov 2, 2008 | Reply

    pls pls can i use dis on my website,what and what gsm companies support this?
    thansks

  5. Keith | Nov 10, 2008 | Reply

    Hi,

    I would like to ask why I can’t send the sms continuously, I can only send 1 sms message. I need to close the application and restart it in order to send the next message.

    Thanks
    Keith

  6. Keith | Nov 11, 2008 | Reply

    Hi,

    My phone supports +CNMI and I set the NewMessageIndication to true. But I still can’t receive the message sent to the phone. Any other setting for it?

    Thanks
    Keith

  7. Tahir | Nov 21, 2008 | Reply

    I am listing a similar question as posted by some of the other users and that is when trying to send a message an exception is thrown that says Object reference not set to an instance of the object. So nothing happens . .no SMS going anywhere..

    also i have tried clicking on the connect button with and without my Nokia 3500 classic GSM mobile attached and in both cases it says successfully connected to modem ..

    any thoughts on this please?

  8. Muhammad Sharkeel | Nov 22, 2008 | Reply

    Hello
    Please tell me when you are going to release version 2 of sms library. i have sucessfully used version 1 for two years and despite for GSM limitation of 300 SMS/Per Hour i found no problem. Currently i tried to switch my phone from Sony Ericsson K510i(working fine) to a better one (w660i) but it did not send message at all neither via cable nor via BT. It did not gave any error and due to some unknown reason message was not sent. Can you help

  9. shanmugavelu | Nov 24, 2008 | Reply

    When i tried to send the following delivery status appear

    Error sending message to . Error sending SMS message: Object reference not set to an instance of an object.

    What is the problem? pls help me.

    Yours truly,

    Shanmugavelu

  10. Vivek | Dec 10, 2008 | Reply

    Dear shanmugavelu, Can you please post the code here.

  11. dotnetmicro | Jan 21, 2009 | Reply

    I used wire2air sms gateway to send and receive sms messages. Their 2way sms api is pretty straight forward, they have some sample vb & c# code too, you can download free sms developer api document from http://www.wire2air.com/smsgateway.asp.

    Have fun !!

  12. John | Feb 6, 2009 | Reply

    hi
    can u send it to me the code in sending and receiving sms with mobile gsm modem?
    tnx in advance

  13. undeserved | Mar 1, 2009 | Reply

    Hi ! I tried your code with my Sony Ericsson W960i model. It is using COM6 in the PORT of the Device Manager in my pc. The program was able to connect to my cell phone when the Connect button is pressed but it gave an error when sending text message.

    Please help.

  14. Vu Tam | Mar 20, 2009 | Reply

    I can send sms, It popup in to erro: Error sending message to . Error sending SMS message: Unknown exception in sending command

  15. Sameer | Mar 20, 2009 | Reply

    please tell me when ver 2.0 will be released ?

  16. Nanjundeswaran.S | Mar 20, 2009 | Reply

    Error sending SMS message: Object reference not set to an instance of an object. I got this Error while using the above code please help me to solve this error

  17. mumu | Apr 3, 2009 | Reply

    thanks thanks a lot ur code for sendng sms s just workng fne vht my phone …ur project s gr8 keep t up thank once agan

  18. Keith | Apr 10, 2009 | Reply

    Can anyone recommend a good unlimited GSM wireless SMS texting plan to signup for? We are about to start a project of using a modem to automatically send/receive text messages. I want to know which wireless carrier is least likely to give me problems with this. Thanks!

  19. Amit Sharma | Apr 13, 2009 | Reply

    hi
    i m new in asp.net using c#.
    i want to make sms application .
    please support me .
    with giving step by step information.

    i m highly thanks to you for this.

  20. Zack | Jun 9, 2009 | Reply

    Hi,
    is this possible to use alphanumeric as sender id when sending sms with .NET SMS Library?
    Any suggestions how to use alphanumeric sender id while i build sms application?
    Thanks a lot..

  21. shekhar abdullah | Jul 4, 2009 | Reply

    Hello, I copy the code.
    but “object not set to an instance object” Error found when sending sms. Plz help….

    [email protected]

  22. Akshayye Sharrma | Jul 11, 2009 | Reply

    Hi There, I am facing the “object not set to an instance object” Error….
    Any help will be appreciated.

  23. Ramesh | Jul 11, 2009 | Reply

    I am using your code . My InterNet with ADSL2 Modem. When i am using BulkSMS Gateway No Error.
    it display “message on Queue” But i am not receive any SMs to my Mobile .
    ?????????

  24. Madhivanan | Aug 5, 2009 | Reply

    Could be please sent me code for me, thnx in advance

  25. Madhivanan | Aug 5, 2009 | Reply

    I have copied the code and try to execute the code but i am getting “Error sending message to . Error sending SMS message: Object reference not set to an instance of an object.”
    Let me know how to fix this

  26. Ranjith | Nov 28, 2009 | Reply

    Hai i`m creating a website i wish to provide free bulk sms service can anyone help me how to do it…

  27. AdForte | Jan 12, 2010 | Reply

    I suggest sms marketing tool http://www.adforte.wordpress.com
    – worldwide
    – can change the sender name
    – get campaign reports
    – import a large contact databases

  28. Ashok | Jan 12, 2010 | Reply

    i am looking for a commercial solution , can u get connected to me in mail ?
    [email protected]

  29. ammarah | Jan 19, 2010 | Reply

    hi.. may i knw the gvn code is for which language?

  30. john | Feb 7, 2010 | Reply

    Which mobile r u using.I want 2 know with which mobile this gateway is working.

  31. imran | Mar 1, 2010 | Reply

    Will u please Tell me How to Empty Memory Store
    if error occurs message memory full..

  32. Pankaj | Mar 9, 2010 | Reply

    I want someone to provide me technicall support to launch a bulk sms site in New Delhi India. I am ready to pay fees. Please contact at 0091-9811731099 or mail at [email protected]

  33. Pankaj | Mar 9, 2010 | Reply

    Hi Mumu can u help me to setup bulk sms service

Sorry, comments for this entry are closed at this time.