RSS Feed for This PostCurrent Article

Bulk SMS Gateway using the Open Source .NET SMS Library


Download Source Code

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

Introduction

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. 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 Post60 Comment(s)

  1. Ivan | Sep 16, 2007 | Reply

    One should always familiarize themselves with the carrier’s terms of service which typically prohibit automated message distribution. This type of functionality has been available for quite awhile but do always keep in mind the legal aspects. The good thing is that automated message reception may not be in violation of TOS so you can get an inexpensive long code without any hustle and with instant network transparency.

  2. Muhammad Shakeel | Sep 18, 2007 | Reply

    I am using this open source library with Sony Ericsson K510i connected via USB cable. I am facing problem that it does not send large sms although my phone supports it (when i type and send sms) it just supports about 140char sms. And one thing more it does not send “_” underscore any sms that contains underscore is stopped by this library.

  3. thoughtworks | Sep 18, 2007 | Reply

    This bug is fixed in the coming release together with other bug fixes. I will release the new version in early October 2007.

  4. Muhammad Shakeel | Sep 18, 2007 | Reply

    Thanks for response and i am waiting for new release

  5. Muhammad Shakeel | Sep 20, 2007 | Reply

    One thing more how can i be the first to know that new version has been released. Is there any place i can register and be automatically notified about future enhancements.

    One more bug (?) that i would like to report, some times even during session the library stops to delete the sent messages automatically even though the option has been enabled but it some how stops deleting the messages and after the storage is filled it stops sending any more messages.
    Thank you very much for developing such a wonderful library and making it open source

  6. thoughtworks | Sep 21, 2007 | Reply

    If you are registered to our website, I will notify you once the new version is released.

    Thanks for reporting the bug !

  7. satria | Sep 21, 2007 | Reply

    I wanna make my thesis with this topic (sms-gateway) but I wanna built it in java. Is the code compatible if I translate it to java lang? and what type of handphone can supported ? thanks before

  8. thoughtworks | Sep 21, 2007 | Reply

    Java has no support for serial communication natively. That is why I don’t use Java in the first place.

    In order to port the code to Java, you may want to have a look at

    Sun JavaComm 3.0 at

    http://java.sun.com/products/javacomm/

    Version 3.0 only supports Solaris SPARC, Solaris x86, and Linux x86.

    JavaComm 2.0 supports Windows, but looks like is not supported anymore.

    You can download version 2.0 here
    http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&
    PartDetailId=7235-javacomm-2.0-spec-oth-JSpec&SiteId=JSC&TransactionId=noreg

    Also look at

    http://www.rxtx.org/

    Both of these 2 libraries are definitely needed should you want to program SMS gateway in Java.

  9. Ivan | Sep 26, 2007 | Reply

    http://smslib.blogspot.com/

    This Java-based sms open source project has been around for years. I’ve used to send and receive sms with mobile phones and GSM modems.

    Enjoy.

  10. Balamurugan | Oct 1, 2007 | Reply

    I am unable to send a sms from ur appication.I am using GPRS NOKIA Mobile.Can u pls Guide Me.I am new to dotnet mobile application.

    thanks in advance

  11. thoughtworks | Oct 1, 2007 | Reply

    Refer to my article at codeproject.com

    http://www.codeproject.com/smartclient/phoneat.asp

    on how to connect to your phone, and also other articles in my blog on how to check your phone capabilities. You must make sure your phone support the required AT commands

  12. srivineel | Oct 15, 2007 | Reply

    sir

    Iam using your bulksms software. I connected
    gsm mobile to pc using datacable using an usb port.But in the software com ports are used so how should i use usb in place of com port

  13. satria | Oct 22, 2007 | Reply

    thanx alot mr.Toughtworks and mr.Ivan for the information. I’ve downloaded the java sms source code from http://smslib.blogspot.com/. i’ll try it :). thanx, GBU all

  14. Muhammad Shakeel | Oct 23, 2007 | Reply

    When is your new release os .net sms library comming. we are waiting anxiously for it.

  15. MAHAGURU | Oct 31, 2007 | Reply

    i am using nokia 3230 but i am not be able to send ne msg software returns exception error

  16. Prendergast | Oct 31, 2007 | Reply

    Really?

  17. Muhammad Shakeel | Nov 2, 2007 | Reply

    Hy Everyone!! can anyone tell me when you people are going to launch version 2 of SMS library

  18. admin | Nov 2, 2007 | Reply

    Version 2.0 is under testing. We need to test it across different handsets, which is not a easy thing. Most probably in a month time.

  19. Muhammad Shakeel | Nov 2, 2007 | Reply

    Thanks admin for your response we are waiting for your release of version 2 thanks again

  20. bilall | Nov 21, 2007 | Reply

    hey! i am not much of the programmer can anyone please tell me. how to use this source code for bulk sms gateway. it would be very kind of you.
    thank you very much

  21. yasir | Nov 26, 2007 | Reply

    hello there! i am running this software of bulk sms gateway. but when i press send button it generates and error message “Object reference not set to an instance of an object.” can u please help me resolving this problem ASAP. thank you.

  22. bappy | Dec 3, 2007 | Reply

    hello sir,

    I’m using Nokia 6300 with USB Cable in COM3, but whenever trying to connect phone than getting a error message. the message is “The I/O operation has been aborted because of either a thread exit or an application request” I think it’s mean that my phone has been used by any other operation but i couldn’t find any application. I hope you can understand my problem. please let me know as soon as possible.

    Thanks in Advance

    bappy

  23. yasir | Dec 3, 2007 | Reply

    Dear bappy!

    The error message is beacuse, your computer is unable to detect a device on the com port u are searching for it, and the reason is you can not connect the COM port with the USB port. 2nd thing is this software is only designed for COM port not for the USB port, your phone 6300 must have bluthooth connection in it, it is much easier to use that to connect it. i have did that as well….i you still face any problem let me know .
    thank you

    yasir

  24. bappy | Dec 3, 2007 | Reply

    hi yasir,

    thanks for your replay. actually i’m connecting by by USB port but it’s showing as COM3 and after clicking on connect button it is being connected. but whenever i’m trying to send message than that error message is being shown. so i’m confuse what’s the problem.

    thanks again

    bappy

  25. sandhya | Dec 15, 2007 | Reply

    hi

    can u please tell me how to put sms in a queue because i’ve made my application online in an asp.net page. it’s giving error when multiple users are sending sms.

  26. Muhammad Shakeel | Dec 18, 2007 | Reply

    Hello All,

    Please tell me when new release of SMS Library is comming. I am facing problem while sending SMS more than about 120 chars. I am using Sony Ericsson K510i connected via USB cable. Any Suggestion? will connecting via BlueTooth solve this problem or changing my phone will solve it.

    Ragrads

  27. FG | Jan 19, 2008 | Reply

    I want to use this library to make commercial product.. do i have to pay.?. (Please say no :) )

  28. admin | Jan 19, 2008 | Reply

    version 1 of the library is under GPL but at this point of time we do not put any constraints if you want to use if for commercial purpose. However, there are quite a number of bugs in this version which are fixed in version 2. We are currently implementing a few other projects and version 2 release is thus delayed.

    The library is a side product from previous project implementation and we will try our best to further enhance it if time permits..

  29. pari | Feb 1, 2008 | Reply

    hi.. without gateways can v send sms from our pc..

  30. Muhammad Shakeel | Feb 6, 2008 | Reply

    Hello Admin.

    Please reply to my message or email me. I want to know which model and connect method you recommend. I am using Sony Ericsson K510i connected via USB cable but I am unable to send SMS more that 120 characters. Please tell me which Phone and model and connect method you have tried to send large (Multipart) SMS

    Best regards
    Shakeel

  31. shubham | Mar 7, 2008 | Reply

    hi i just want know how to use that progfram and can i send bulk sms on mobile through it and if yes pz tellme how and tx

  32. Farukh Gee | Mar 13, 2008 | Reply

    (shubham) short answer for your Q is, Connect your mobile with PC(cable,bluetooth or infra), select correct port (get it from ‘Device Manager’), enter required values and send short message.
    Thank you for using our library. GoodLuck.

  33. senjahitam | Mar 15, 2008 | Reply

    dear sir…
    i’m currently doing my project with this topic (sms-gateway). i work it in VB.net 2005. in my project, i just wanna send a message. and of course i need status of delivery [sent/delivered,pending,failed]. how can i do this?

    thanks before.. regards

    P.S : i’m sorry my english terible.. a’m not expert in english. i from indonesia.

  34. senjahitam | Mar 15, 2008 | Reply

    i forget… i use phone Sony Ericsson K610i

    thanks again

    regards,

  35. Farukh Gee | Mar 17, 2008 | Reply

    (senjahitam) If SMS-Gateway is your project then download the source code whose link is give on top of page and understand this great example by author. Take this project as an example, and proceed according to your project requirements.
    Thank you for using our library. GoodLuck.

  36. senjahitam | Mar 17, 2008 | Reply

    [Farukh Gee]
    thanks for your advice sir. i was download example source code [Send SMS through GSM modem or CellPhone using .NET SMS Library] but i still can’t send sms to another phone. is there any code to be added or modified? or my phone not supported? would u like to give me some explanation? because i’m a beginner in this project. thanks again.

    regards

  37. Zurich Ferdian | Apr 21, 2008 | Reply

    Hi I’m using ATSMS library for an sms gateway application I’m developing, can you tell me the code to delete the sms messages(received and sent) in the modem storage and in the SIM card?

  38. sani | Apr 22, 2008 | Reply

    I have a question.
    What is the advantages to try to send ms via a GSM modem? since the GSM modem needs a SIM card to work, you still need to paie your provideur when sending or receiving some SMS right?

    Thanks in advance.

  39. Zeyad B | Apr 30, 2008 | Reply

    Thanks for your post and code,

    I have tried it and successfully sent messages through it, but the phone number is shown, it’s not hidden sender message. Is it possible to send hidden sender messages by working around the pdu string?

    thank you

  40. rrrrrrrrrr | Jun 12, 2008 | Reply

    Hi I’m using ATSMS library for an sms gateway application I’m developing, can you tell me the code to delete the sms messages(received and sent) in the modem storage and in the SIM card?

  41. Jesper Møller | Jun 20, 2008 | Reply

    Hi Admin

    Do you still working on the new release of the library version 2? or do you not working on that anymore?. Im waiting anxiously for it.

  42. dagwaping2000 | Jul 27, 2008 | Reply

    I tried sending messages using the BulkSMS but encountered an error “Error sending message to . Error sending SMS message: Unknown exception in sending command” with error code 4006. What seems to be the problem? I tried sending SMS using hyperterminal and AT Commands, it’s successful.

  43. Rafa | Jul 31, 2008 | Reply

    I’m testing your library, is good for me
    I have problem in nokia N70 and S65, problem return is,

    Error sending message to . Error sending SMS message: Unknown exception in sending command

    Please is possible help me.

    King Regards
    Rafa

  44. Rafa | Jul 31, 2008 | Reply

    update info problem, error code is 4006

    Tanks you
    Rafa

  45. dagwaping2000 | Aug 1, 2008 | Reply

    My next problem is that sometimes when I received the SMS using the NewMessageReceived Event, there’s no MSISDN or mobile no of the sender. What do you think is the problem?

  46. Send Direct Bulk SMS | Sep 16, 2008 | Reply

    Offering Software for free download and Send Direct Bulk SMS

    XL Studio v 3.4
    SMS Plug-in for Microsoft Excel®.

    “Time saved is money earned”.

    If you have Microsoft Excel®, send direct bulk SMS with it. If you too believe, that saving time by utilizing it to the maximum will enhance your working; then this offer is best suited to you. No matter what profession you are into, reaching out to a wide base of people is a part of it. And if you want to do this in a matter of a few seconds - XL Studio 3.4 is what we have to offer. It is easy to use software that will help you to reach out to a number of people directly.

  47. Vivek | Sep 27, 2008 | Reply

    It takes very long to send a single SMS. Can you please tell me why is it so ?
    I’m using an IR connection.

  48. Farukh Gee | Sep 28, 2008 | Reply

    (Vivek) It is because Text transfer from your computer to your Mobile through IR is taking time. IR is alot slower then Bluetooth and Cable. Try again with BT or Cable.

  49. Sameer | Oct 1, 2008 | Reply

    hello there! i am running this software of bulk sms gateway. but when i press send button it generates and error message “Object reference not set to an instance of an object.” can u please help me resolving this problem ASAP. thank you.

  50. Vivek | Oct 5, 2008 | Reply

    Can I have the source code of the DLLs, viz. ATSMS& ATSMS.ctrl ?

  51. 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.

  52. 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 ?

  53. 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

  54. abiola | Nov 2, 2008 | Reply

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

  55. 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

  56. 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

  57. 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?

  58. 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

  59. 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

  60. Vivek | Dec 10, 2008 | Reply

    Dear shanmugavelu, Can you please post the code here.

RSS Feed for This PostPost a Comment