Dear reader, today we will discuss a very important topic, sending SMS alerts to a mobile phone that is a common demand of most clients. I have experience developing donation collection software. In that software we used a GSM Modem to send a SMS thanks to the donor. So we developed a small application that runs on the server and sends a SMS whenever a new record is inserted into the database from any client.
In this application we will use the following:
- GSM Modem (I have used Vodafone; you can use any)
- SIM Card.

Step 1
Create the table in SQL Server.
CREATE TABLE [dbo].[Donor_Profile](
[Don_Date] [datetime] NULL,
[Don_Donor_ID] [varchar](20) NOT NULL,
[Don_Donor_Name] [varchar](50) NULL,
[Don_Mobile_Phone] [varchar](50) NULL,
[Don_Member] [varchar](10) NULL,
[Don_SMS1] [varchar](10) NULL,
[Don_SMS2] [varchar](10) NULL,
[Don_Logo] [image] NULL,
[Don_Donor_Type] [int] NULL,
CONSTRAINT [PK_Donor_Profile] PRIMARY KEY CLUSTERED
(
[Don_Donor_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]Step 2
Now you can insert any record in the table but please make sure to insert:
[Don_Donor_ID]= CF-00001-12 and leave the [Don_SMS1], [Don_SMS2] field NULL, [Don_Mobile_Phone] please enter valid phone number where you want to receive the SMS.
Step 3
Create the new Desktop application.

Step 4
Design the form as shown in the picture.

Step 5
Dear Reader, please read this carefully in this step we need to include the following DLL files in the bin\ Debug folder:
- GSMCommServer.dll
- GSMCommShared.dll
- GSMCommunication.dll
- PDUConverter.dll
Step 6
Now we need to add the reference to the project as shown in the picture.


Step 7
Now we have added one more reference.

Step 8
Now we need to move to the code behind window and use these references in the code.

Step 9
Now we need to add few textboxes and private variables that we will use in our code.

Step 10
Now we will add the two classes Operation and Main as in the following and add two methods in it GetDBConnection, ipconfig and Execute.


Step 11
Now add the following code in the form load event.

Step 12
Now add the following code in the connect button click event.

Step 13
Now add the following code in the send button click event.

Note: Dear reader please don't worry, I have attached the source file for your reference. No need to type in the entire code. But you need to change the SQL Server setting correspondingly for your own system.
For example:
- SQL Server instance na
me.(.\\CRMIS)
- SQL Server user name and password.(user id sa password.###Reno123)
- Initial Catalog=PSH (database name)
Add the public static class in the Main.cs as in the following:
public static SqlConnection GetDBConnection()
{
SqlConnection conn = new SqlConnection(
"Data Source=.\\CRMIS;Initial Catalog=PSH;User ID=sa;Password=###Ren0321");
return conn;
}Step 14
Now we need to attach the modem to the system. It will install its own application but keep this point in your mind, you need to close the application after the installation is complete because that software captures the port that we will use in our code.
Picture 1

Picture 2 (let this application to be installed and close it when it is finished).

Step 15
Now run the application; press F5.

First we need to select the port name from the drop-down menu then press the connect button; if port is not valid then it will show the error message.

Now I will select port COM4; it will connect successfully. Dear reader, you need to check your port one by one; Windows XP normally uses port COM3 or COM4.

Step 16
Now press the "Send SMS button"; you will then get a SMS on your mobile phone as in the following:

NOTE: Dear reader, the code works 100%; please contact me if you have any query regrarding this article.


DeveloperPosted Aug 5, 2024, 1:28 AM EDT
GSM modem required or not
cletus igbePosted Nov 28, 2023, 9:06 AM EST
I followed your instructions above and code my project, it works 100%. My question now is how can we add a condition to check if message was sent successfully?
cletus igbePosted Nov 28, 2023, 9:03 AM EST
Thank you.
RuhulPosted Feb 1, 2021, 10:22 PM EST
Where is your source file ?
Zeeshan RehmatPosted Nov 17, 2020, 6:51 PM EST
Message send successfully but i am getting the exception e.g "No data received from phone after waiting for 25016ms."
Jorshy ChanPosted Jun 27, 2020, 6:30 AM EDT
For texts with more than 160 characters?
Kenfack CathyPosted Apr 15, 2020, 2:21 AM EDT
Les etapes un et deux je ne les comprends vraiment pas , enfaite je n'ai pas encore execute votre solution , jusqu'ici les questions que je vous pose sont celles que j'ai rencontre en implementant ma solution par moi mm, une fois que j'ai vu votre solution elle m'a intererser c'est pourquoi je vous pose des questions , et aussi je ne toruve pas le lien du fichier svp merci
Kenfack CathyPosted Apr 15, 2020, 2:15 AM EDT
Mr svp ou es qu'on entre le message qu'on veut envoyer, merci.
Kenfack CathyPosted Apr 15, 2020, 2:14 AM EDT
Mr svp j'ai vaiment besoin de vos reponses je travaille actuellement sur ce projet: application d'envoie sms partout dans le monde grace a un modem gsm en C# ceci est le projet sue lequel je travail j'ai vraiment besoin de votre aide . merci mr
Kenfack CathyPosted Apr 15, 2020, 2:12 AM EDT
Svp j'aimeerais egalement savoir si c'est possible d'envoyer les messages partout dans le monde avec ceci.
Kenfack CathyPosted Apr 15, 2020, 2:09 AM EDT
Salut mr svp comment choisi le port COM qui communiquera avec notre modem , la je suis perdu , quand je me rends dans les paremetres de ma machine j'ai plusieurs ports COM d'autre avec le mot in use devant je ne sais quel utilise. merci
Benjamin CerdenaPosted Jan 11, 2020, 11:13 PM EST
Hi! how can I download your .rar file?
Rolando MotaPosted Oct 10, 2019, 10:07 AM EDT
Hello, do you know that it works for windows 10? I am working with BAM huawei with connection USB, but I can not detect it as port serial connection, can you help me??
raffie gollayanPosted Aug 15, 2019, 3:59 PM EDT
An unhandled exception of type 'GsmComm.GsmCommunication.CommException' occurred in GSMCommunication.dllAdditional information: No phone connected. Can't seems to find any answer in the web please help.
shahid hussainPosted Feb 13, 2019, 4:35 PM EST
Can we use mobile phone instead of gsm modem??
Said HussainPosted Jan 7, 2019, 6:41 PM EST
Hi sir how i can send urdu sms
Zeshan RaoPosted Nov 25, 2018, 10:16 PM EST
Hi Sir , I want to send sms through mobile except GSM device .. Is it possible ? if possible then how ?
Dwight PerelloPosted Nov 12, 2018, 3:48 PM EST
Hi, I am using GSMCOmm library as well. just wondering what seems to be the problem because for whatever reason it just stop receiving text msgs. It was working fine before and I can still send sms but not receive
zahra mbeigyPosted Oct 18, 2018, 2:02 AM EDT
Hi, Mr, Naveed, im getting this error 'Could not find file 'C:\...\bin\Debug\IPCONFG.txt'.why/
Javed IqbalPosted Oct 5, 2018, 1:28 AM EDT
Hi, I have included GSMCommServer.dllGSMCommShared.dllGSMCommunication.dllPDUConverter.dll from Debug folder but still it cant reference to those dlls in code...
George FergusonPosted Sep 25, 2018, 1:15 PM EDT
Thanks a lot. It really worked. Please can the senders number be changed to Name. Please this is my Email: [email protected]
Rey ManjaresPosted May 26, 2018, 1:34 AM EDT
Hi again Mr. Naveed, I've got the issue fix already, but I have one question, does this api can handle a scenario, which will display a title/name instead of the sender's number? thank you in advance for the accommodation.
Rey ManjaresPosted May 26, 2018, 12:57 AM EDT
Hi Mr. Naveed, Im getting this error "Message service error 500 occurred." can you please help me rectify this issue. Thank you in advance.
Sayed ShoaibPosted Mar 28, 2018, 10:46 AM EDT
Sir I want to send SMS from c# what should I use gsm module or api which one is inexpensive and give good services.
shanigarapu rakeshPosted Feb 4, 2018, 8:22 PM EST
Its not working. Exception like "Message service error 500 occurred."
Prince KhanPosted Jan 29, 2018, 12:51 AM EST
Does'nt work its fake
Saikat MekdarPosted Nov 16, 2017, 9:14 PM EST
Hello sir,How to show sent and received messages into this application?
josua edwardPosted Sep 21, 2017, 7:31 PM EDT
Hello sir, do you use any gsm module? or modem?
Salman MushtaqPosted Sep 17, 2017, 3:57 AM EDT
Can I use my mobile phone instead of modem?
cobra TwoPosted Jun 3, 2017, 12:25 PM EDT
Thank You it works fine
jitendra singhPosted May 1, 2017, 10:03 PM EDT
Hi sir can i do recharge using this method on USSD ocde
Rémili AbirPosted Apr 4, 2017, 6:34 AM EDT
At first when i connect the modem using connect button then show modem connected successfully but when i send message using send button then show modem is not available ,ansewer me and thank you
blue dovePosted Mar 5, 2017, 12:30 AM EST
If I want to send sms to multiple students what changes should I made in this code?
Ritesh SinghPosted Jan 30, 2017, 7:43 AM EST
Its working fine sir ...thanks a lot ..!!
Lahoucine JapetPosted Jan 4, 2017, 5:49 AM EST
I get an error when i try to connect Error message "Unable to open port COM.."
xzaq 8520Posted Dec 25, 2016, 7:40 AM EST
"No phone connected." Error is giving ... Please Help..
xzaq 8520Posted Dec 25, 2016, 7:39 AM EST
"No phone connected." Error is giving
anwar hossainPosted Jul 22, 2016, 1:23 AM EDT
At first when i connect the modem using connect button then show modem connected successfully but when i send message using send button then show modem is not available why Please give the answer..
Zubair KatalPosted Feb 21, 2016, 1:13 AM EST
i'm using ptcl evo having a sim in it but it is not connecting to the application... GSM modem is not availabe exception is throwing .. what is the problem with that ..??
Ravi AgrawalPosted Feb 9, 2016, 11:05 PM EST
I want to use in the web application to send and receive SMS in db. Please tell me how is that possible.
Ravi AgrawalPosted Feb 9, 2016, 11:02 PM EST
Is it work on usb port. If not then how we can change code for USB port.
Tharuka KannangaraPosted Jan 13, 2016, 11:01 PM EST
how to send bulk sms using this
Yaseen UlHaqPosted Jan 3, 2016, 6:42 AM EST
is valid and modem connected in this senario
Yaseen UlHaqPosted Jan 3, 2016, 6:42 AM EST
i am using samsung gelaxy grand prime and port no 5
Yaseen UlHaqPosted Jan 3, 2016, 6:42 AM EST
the code is in working condition but i am facing different time different error
Yaseen UlHaqPosted Jan 3, 2016, 6:41 AM EST
dear port not open error
Rizwan UllahPosted Oct 23, 2015, 7:47 AM EDT
to all those who are getting this error ""Phone not connected " or "Message not Sent"... there is a logical error in this code. if you are using a nokia phone.. then port number should be 4 or com4 and baud rate should be 112500 and timeout should be 300, AND ALWAYS CLOSE THE PORT WHEN MESSAGE IS SENT, IF PORT IS LEFT OPEN IT WONT CONNECT 2ND TIME AND WILL GIVE ERROR..
Mohammad InayatullahPosted Sep 17, 2015, 2:12 AM EDT
Hi, I am getting the error "Text is too long. A maximum of 140 resulting octets is allowed. The current input results in 392 octets." can you please guide me.
Mohammad InayatullahPosted Sep 17, 2015, 2:12 AM EDT
Hi, I am getting the error "Text is too long. A maximum of 140 resulting octets is allowed. The current input results in 392 octets." can you please guide me.
sona gharagyozyanPosted Aug 31, 2015, 12:58 AM EDT
Hi, I am getting the following error "SMS not sent". But modem connected successfully. What could be the reason? Please help, Thank you.
Denes AntonioPosted May 9, 2015, 1:39 PM EDT
how i send more than 160 character?
DarinPosted Feb 9, 2015, 12:38 AM EST
there is errror in the code
Sourabh SomaniTOP 100Posted Feb 8, 2015, 4:14 AM EST
Very Nice sir
DarinPosted Feb 4, 2015, 2:03 AM EST
i got an error saying that the name 'code' does not exist in the current context.
Sunil SinghPosted Dec 4, 2014, 12:17 AM EST
Hi, I am getting the following error 'No phone is connected' and its from the following line of code: "comm.SendMessage(pdu);". Although when I connect it says 'Modem connected successfully.' Please help to rectify the error.
kawsar hmedPosted Nov 29, 2014, 12:22 AM EST
Hi , Can i use this project in windows 7
Ahmad -Posted Nov 26, 2014, 3:44 AM EST
Hi, How can I get and show delivery report?
venkadesan perumalPosted Nov 20, 2014, 11:12 PM EST
please check your balance
Kingsley BainnPosted Oct 31, 2014, 3:08 AM EDT
Hi, I am getting the following error 'No phone is connected' and its from the following line of code: "comm.SendMessage(pdu);". Although when I connect it says 'Modem connected successfully.' I need your help asap.
Vi Lâm TrươngPosted Sep 28, 2014, 5:43 PM EDT
why did you identify numberphone "left(Don_Mobile_Phone,4)+right(Don_Mobile_Phone,7)", that made my number wrong.. Example my number is +84973905046. Please help me resolve !!! Thank you!
Danish SiddiquiPosted Aug 15, 2014, 4:43 AM EDT
let me if this code will work on any mobile or this code will need some specific phone models or GSM model kindly let me know as soon as possible me email id is [email protected]
Danish SiddiquiPosted Aug 15, 2014, 4:41 AM EDT
Hello Naveed,
Bilal BhatiPosted Aug 12, 2014, 12:05 AM EDT
plz guide ?????
Bilal BhatiPosted Aug 12, 2014, 12:05 AM EDT
how to modify this code using mobile phone ????
Rahul MPosted Jul 22, 2014, 2:03 AM EDT
Hi Naveed , I tried to use your sample. I am receiving exception at comm.open(). Exception message is "Can not open part <port no.> : The file is being used by some another process.". I tried with Nokia phone connected over bluetooth and Tata Photon dongle , in both the cases received same exception. Can you please suggest any workaround/solution?
merid fikaduPosted Jul 18, 2014, 12:00 AM EDT
hi dear is it k if i use my phone like GSM modem!!!????
Vinodhini BaskarPosted Jul 12, 2014, 5:54 AM EDT
anybody can tell how to run this program emergency
Abdullah ahmedPosted Jul 8, 2014, 4:09 AM EDT
any webservices sir then plz email me i want to make web application plz help me [email protected]
Gil TECPosted Jul 4, 2014, 6:49 AM EDT
thanks
mahdi ghPosted May 18, 2014, 12:13 AM EDT
Hi how to send unicode characters?
Choujoun BououniPosted May 14, 2014, 5:13 AM EDT
Hi can i use instead modem my phone nokia
Naveed ZamanPosted May 13, 2014, 4:23 AM EDT
please check modem conection or check the different ports
venkadesan perumalPosted May 3, 2014, 6:00 AM EDT
Hi Naveed Zaman , i am try to use your code , but i am getting one exception for ' No phone connected' while sent SMS. the COM Port Connected.
Raisul AlamPosted Apr 9, 2014, 7:33 PM EDT
Dear Naveed, How to send Sender name ? Can you Help me??
Raisul AlamPosted Apr 9, 2014, 3:17 AM EDT
Dear Naveev, Thanks a lot from the bottom of my heart, How can I run it from webform
Former memberPosted Mar 25, 2014, 11:55 PM EDT
Hi! Great article! If you wish to send/receive mass amount of text messages with a c# example, just check out the following webiste:http://www.ozekisms.com/index.php?owpn=315&info=c_sharp_sms_example
sloqye sloqyePosted Mar 4, 2014, 10:00 AM EST
Thanks.
Afzal HossainPosted Feb 19, 2014, 9:25 PM EST
Thanks You
Afzal HossainPosted Feb 19, 2014, 9:24 PM EST
Nice Work........!
m vPosted Dec 20, 2013, 9:23 PM EST
tank you
Ali SadeghiPosted Dec 15, 2013, 9:42 PM EST
mr naveed thanks for your good article about sending sms. i used it and it works without any problem.but when i use words like"????" or"????? " with unicode characters as a message text it does not work and the error massage is "modem is not available" .can you please tell me what can i do for solve the problem.Thanks in advance
Naveed ZamanPosted Nov 23, 2013, 3:18 AM EST
thanks for the appreciation. but i am not getting the problem. modem connected but when you sending the sms it not receiving on the cell phone ? please clear the question so that i can help you out.
abc defPosted Nov 21, 2013, 6:36 PM EST
Naveed thanks for the article. I am getting No phone connected when sending sms, Modem connected successfully. Its airtel modem with 3G sim card. Can you please tell me what could be the reason? Thanks in advance
muthu kumarPosted Oct 3, 2013, 4:30 AM EDT
Thanx lot its working....but did some modulation.....its working
Teboho NtoahaePosted Sep 30, 2013, 2:51 AM EDT
hello.. Can I send an image to a cell phone using the above code? if not, do you know of anyway? thank you
Ashutosh TripathiPosted Sep 20, 2013, 3:43 AM EDT
nice work..
varun kumarPosted Sep 18, 2013, 5:00 AM EDT
hello naveed sir . i tried this code but some error in com1,2,3,4, . i have vodafone dongle and airtel sim . but not sended the sms,via c#,.
Hussain afridiPosted Sep 3, 2013, 8:33 AM EDT
sir how can set the "COM1,COM2,COM3...." the fix..
Naveed ZamanPosted Sep 1, 2013, 9:00 AM EDT
thanks for reading my article. please tell me where your got error on connection with modem or sending SMS?
akash agrawalPosted Aug 31, 2013, 10:39 AM EDT
I m using Reliance 3g modem, your code is not working in my prospective i did all thing as you said please can you help me to successfully run your code.....
Sharad GuptaPosted Aug 30, 2013, 10:40 PM EDT
nice one Naveed
Hussain afridiPosted Aug 29, 2013, 10:43 AM EDT
Love you Sir Naveed for nice work... and which country you belong ??
junaid faisalPosted Aug 26, 2013, 1:31 AM EDT
Nice work bhai jaan....................how can we reiceve sms using ur solution
Pramod LawatePosted Aug 25, 2013, 8:26 AM EDT
Naveed great work .........it's nice article by you
Naveed ZamanPosted Aug 24, 2013, 10:13 PM EDT
i am glade i have contributed small pace of token for my community. I love my community (C-SHARPCORNER)
anand kulkarniPosted Aug 23, 2013, 10:54 PM EDT
Good Work
Former memberPosted Aug 22, 2013, 3:44 AM EDT
Nice article
Abhishek JainPosted Aug 22, 2013, 3:11 AM EDT
Nice article...
Naveed ZamanPosted Aug 21, 2013, 9:10 PM EDT
i am honored
Ravi ShekharPosted Aug 21, 2013, 8:58 PM EDT
Nice article..sir.
Mahesh ChandTOP 10Posted Aug 21, 2013, 9:06 AM EDT
Awesome Naveed. Thank you for taking care of it right away. Entire C# Community appreciate your work.
Naveed ZamanPosted Aug 21, 2013, 7:41 AM EDT
thanks for your interest in my article source is added in Article Extensions
Mahesh ChandTOP 10Posted Aug 21, 2013, 7:18 AM EDT
Yes same download problem. Naveed, it will be nice if you could zip the code or upload it again?
Jay ParekhPosted Aug 21, 2013, 3:55 AM EDT
Gives error while Downloading File GSMModem.rar