Click here to Skip to main content
12,698,358 members (23,172 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


119 bookmarked

Bulk SMS Sender

, 18 Aug 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Sending multiple / bulk SMS through Excel file to multiple recipients using GSM phone or GSM modem

Main Start-up Screen

Main Screen Of Bulk SMS Sender


This is a simple SMS application using free GSM Communication Library GSMComm for sending bulk SMS to multiple numbers of recipients using an Excel file for all our messages and recipients' numbers.


It is very helpful for learning how to send SMS through C# using free GSM Communication Library with minimal efforts.

Using the Code

So now let's go on the actual code. The first step is that you need to get connected your GSM Phone / GSM Modem to your PC assuming that you have connected your device to PC and all the necessary drivers are loaded and it is connected successfully.

For connecting device using GSM COMMUNICATION LIBRARY, you have to download GSM COM LIb from and reference it in your project. Then use it in your project:

using GsmComm.GsmCommunication;
using GsmComm.Interfaces;
using GsmComm.PduConverter;
using GsmComm.Server;

And construct the initial necessary information for connection and GSMComm class.

public static Int16 Comm_Port = 0;
public static Int32 Comm_BaudRate = 0;
public static Int32 Comm_TimeOut = 0;
public static GsmCommMain comm;

Bingo! After connecting your device to your PC, run the project and the above shown main screen will appear, now press Get COM Port List button on main screen to get all Ports information in to the DataGrid.

COM Port List Of System

All the COM Port Lists in the System will appear in the Grid Box as shown above.

For getting the COM Port List and additional data of COM Ports, Microsoft has provided us a utility Called "WMI CODE CREATOR" which can easily create C# code for that purpose. Google it and download to your PC, it will give you thousands of classes / methods / properties to get the system information with minimal efforts of system programming.

Here is how I get all the COM Port Information with all the additional device information:

//     Here we are getting the all available information from the Win32_SerialPort 
//     and setting it in to the DataGrid

                ManagementObjectSearcher searcher =
                new ManagementObjectSearcher("root\\CIMV2", 
            "SELECT * FROM Win32_SerialPort");
                foreach (ManagementObject queryObj in searcher.Get())
                    if (queryObj != null)
                        object captionObj = queryObj["DESCRIPTION"];
                        object capdeviceid = queryObj["DEVICEID"];
                        object MaxBaudRate = queryObj["MAXBAUDRATE"];
                        object connstatus = queryObj["STATUS"];
                        string timeoutsec = "100";

                            dataGridView3.Rows.Add(capdeviceid, captionObj,
                                MaxBaudRate, timeoutsec, connstatus);

var i = C#; 

If you get all the COM Port Information from system without error, then the second step is to connect to the device, click on the Cell of Data Grid of your desired device to connect. As shown below, a Confirmation message will appear and Connected device information will also be shown and DataGrid Cell will be highlighted green.

Connection Confirmation

Connection Confirmation

How to Connect to GSM Device / Phone

Try GSMComm connection with the values got from the DataGrid when Cell is Clicked.

//FOR GsmCommMain we give three arguments (PORT , BAUD RATE , TIMEOUT SEC)

Comm_Port =     Convert.ToInt16(dataGridView3.Rows[i].Cells[0].
Comm_BaudRate = Convert.ToInt32(dataGridView3.Rows[i].Cells[2].Value.ToString());
Comm_TimeOut =  Convert.ToInt32(dataGridView3.Rows[i].Cells[3].Value.ToString());

comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut);

     if (comm.IsConnected())
         //Something to do when device connected

Getting Phone Information after successful connection:

//Getting phone information through IdentificationInfo Structures of GSMComm ...

    Phone_Name.Text = comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
    Phone_Model.Text = comm.IdentifyDevice().Model.ToUpper().ToString();
    Revision_Num.Text = comm.IdentifyDevice().Revision.ToUpper().ToString();
    Serial_Num.Text = comm.IdentifyDevice().SerialNumber.ToUpper().ToString();

After successfully connecting with the device, now it's time to send a word out there. :-)

Let's Check Out Single SMS Sending TAB

For Sending Single SMS Single SMS Message Sent

//For sending single SMS with minimal code

//For SmsSubmitPdu we give three arguments (SMS TEXT , RECIPIENTS NUMBER , ENCODING )

string CELL_Number, SMS_Message;

SmsSubmitPdu pdu1;

CELL_Number = Cell_Num.Text.ToString();
SMS_Message = SMS_Text.Text.ToString();

     pdu1 = new SmsSubmitPdu(SMS_Message, CELL_Number, "");
     MessageBox.Show("M E S S A G E - S E N T", "Information", MessageBoxButtons.OK,

For sending multiple SMS from Excel file, here's how you can achieve this:

//Below code on button click will Open File Select Dialog Box
//for Excel File which contains Sheet name SMS and only two columns named
//CELL NUMBER and MESSAGES which will be loaded in to DataGridView

//Also you need to rename your Excel sheet to SMS because 
//it is also checking that sheet name

        private void button3_Click_1(object sender, EventArgs e)
            int rows_counting, column_counting1 = 0;
            OpenFileDialog dialog = new OpenFileDialog { };
            dialog.Filter = "SMS Sending File(*.xlsx;*.xls)|*.xlsx;*.xls";
            dialog.Title = "Select Excel File For SMS";
            DialogResult dlgresult = dialog.ShowDialog();
            if (dlgresult == DialogResult.Cancel)
                MessageBox.Show("You Cancelled !!!");
                string sms_filename = dialog.FileName;

                if (System.IO.File.Exists(sms_filename))
                        Cursor.Current = Cursors.WaitCursor;

                        string connectionString = String.Format(
                @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};
                Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""",

                        string query = String.Format("select * from [{0}$]", "SMS");
                        OleDbDataAdapter dataAdapter = new OleDbDataAdapter
                    (query, connectionString);
                        dataSet = new DataSet();
                        dataGridView1.DataSource = dataSet.Tables[0];
                        dataGridView1.AutoSizeColumnsMode = 
                        rows_counting = dataGridView1.RowCount - 1;
                        column_counting1 = dataGridView1.ColumnCount;

                        if (column_counting1 < 2 || column_counting1 > 2)
                            MessageBox.Show("Kindly Check Column Count 
                    in Excel Sheet !!!\r\n\n
                               There Should Be Only Two Columns in Sheet Like Below\r\n\n
                               CELL NUMBER | MESSAGES", "Error", MessageBoxButtons.OK,

                        if (    dataGridView1.Columns[0].Name.ToString().ToUpper() == 
                    "CELL NUMBER" &&
                                dataGridView1.Columns[1].Name.ToString().ToUpper() == 

                            label25.Text = "Total SMS In Excel File " + rows_counting;
                            MessageBox.Show("Data Imported Successfully...!!!\r\n\n
                               Check Imported Values & SEND SMS.....!!!!",
                              "Information", MessageBoxButtons.OK,
                            MessageBox.Show("Column Names 
                Are Not In Specified Format !!!",
                              "Error", MessageBoxButtons.OK,
                    catch (Exception E6)
                        MessageBox.Show("Error Loading 
            Excel FIle\r\n\nKindly Check Worksheet Name",
                            "Error", MessageBoxButtons.OK,

After loading Excel file into the DataGrid, we'll only use the For Loop function to get CELL NUMBER & MESSAGE one by one and send it using very simple code just like for sending a single SMS message.

string MSMS_Number, MMessage;
   int i;
   SmsSubmitPdu pdu3;
       if (comm.IsConnected()==true)
                   for (i = 0; i < dataGridView1.RowCount - 1; i++)
                       MSMS_Number = dataGridView1.Rows[i].Cells[0].Value.ToString();
                       MMessage = dataGridView1.Rows[i].Cells[1].Value.ToString();
                       pdu3 = new SmsSubmitPdu(MMessage, MSMS_Number, "");
                       //Sleeps system for 1000ms for refreshing GSM Modem / Phone

                Cursor.Current = Cursors.Default;

                MessageBox.Show("T O T A L - M E S S A G E - S E N T = " + i,
                        "Information", MessageBoxButtons.OK,

Simple, isn't it? If not, send me a question and I will be glad to help you out.

And for extra spice, I have added simple checking when Excel File is loaded into DataGridView when CHECK VALUES button is clicked, it will check for NULL VALUES and Message text more than 160 Characters and highlighted cells to RED if an error is found, or else cells will be green if no error is found.

For achieving cell checking, a simple yet once again FOR LOOP will do the magic. ;-)

//On Check Values button below code will check cell values 
//One By One and set the color either RED or GREEN
//if <b>IF STATEMENT</b> passes

private void button7_Click(object sender, EventArgs e)
    for (int i = 0; i < dataGridView1.RowCount - 1; i++)
        for (int j = 0; j < dataGridView1.ColumnCount ; j++)
            if (    dataGridView1.Rows[i].Cells[j].Value.ToString() == "" ||
            Value.ToString().ToUpper() == "-" ||
                            dataGridView1.Rows[i].Cells[j].Value.ToString().Length > 160 )

                  //Setting Cells Background color to RED if above 
                  //Error Found in Any of the cells

                  dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Red;

                  //Setting Cells Background color to GREEN which passes 
                  //above validations

                  dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Green;
                  button4.Enabled = true;

That's all folks... happy coding... Let the SMS begin !!! :-)

Points of Interest

You should try WMI CODE CREATOR. It will give lots of help to explore system information.


This is actually a much smaller version of code made for a much larger project for some specific purpose for sending bulk SMS to fellow Team Members. :-)

Bulk SMS SENDER Ver 1.0


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Fahad Rafiq
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionNonsensical Link Pin
Robert Everett28-Nov-16 2:51
memberRobert Everett28-Nov-16 2:51 
Questioni think this will not work Pin
Ali Zee19-Nov-16 7:58
memberAli Zee19-Nov-16 7:58 
QuestionNo load file xls or xlsx Pin
Member 1189549323-Oct-16 19:00
memberMember 1189549323-Oct-16 19:00 
Questionconnect GSM modem to a website and send sms in realtime Pin
Member 127218525-Sep-16 19:11
memberMember 127218525-Sep-16 19:11 
QuestionMessage Removed Pin
hristo prodanov5-Sep-16 20:27
memberhristo prodanov5-Sep-16 20:27 
QuestionMessage Removed Pin
mila wilson5-Sep-16 20:27
membermila wilson5-Sep-16 20:27 
Questionconnect GSM modem to own website to send sms in real-time Pin
mila wilson5-Sep-16 20:27
membermila wilson5-Sep-16 20:27 
QuestionCan't work with the excel files in xls / xlsx formats for Bulk SMS Sender Project Pin
MKHasan21-Aug-16 19:26
memberMKHasan21-Aug-16 19:26 
Questionerror converting COM port settings values Pin
Member 1163821919-Jun-16 19:39
memberMember 1163821919-Jun-16 19:39 
Questionphone is not connected Pin
Member 1258479117-Jun-16 8:40
memberMember 1258479117-Jun-16 8:40 
Questionhow to use this programm using usb key Pin
Member 124254429-May-16 1:29
memberMember 124254429-May-16 1:29 
AnswerRe: how to use this programm using usb key Pin
Fahad Rafiq30-May-16 19:40
memberFahad Rafiq30-May-16 19:40 
AnswerRe: how to use this programm using usb key Pin
Member 1258479117-Jun-16 8:38
memberMember 1258479117-Jun-16 8:38 
QuestionBULK SMS Pin
Member 123934991-Apr-16 4:25
memberMember 123934991-Apr-16 4:25 
AnswerRe: BULK SMS Pin
Fahad Rafiq30-May-16 19:44
memberFahad Rafiq30-May-16 19:44 
QuestionThrowing error "No Phone Connected" Pin
Barsan Baris24-Feb-16 23:51
memberBarsan Baris24-Feb-16 23:51 
QuestionBulk-SMS-Sender Pin
hs777it16-Feb-16 4:14
grouphs777it16-Feb-16 4:14 
AnswerRe: Bulk-SMS-Sender Pin
Fahad Rafiq30-May-16 19:46
memberFahad Rafiq30-May-16 19:46 
AnswerRe: Bulk-SMS-Sender Pin
Ali Zee19-Nov-16 7:56
memberAli Zee19-Nov-16 7:56 
QuestionApplication hang when try sms more than 30 messages Pin
aminvincent15-Feb-16 22:06
memberaminvincent15-Feb-16 22:06 
AnswerRe: Application hang when try sms more than 30 messages Pin
Fahad Rafiq30-May-16 19:47
memberFahad Rafiq30-May-16 19:47 
AnswerRe: Application hang when try sms more than 30 messages Pin
Fahad Rafiq30-May-16 19:52
memberFahad Rafiq30-May-16 19:52 
QuestionMemory leak when unplug the cable Pin
Imran Kanjoo14-Nov-15 19:56
memberImran Kanjoo14-Nov-15 19:56 
Elijah O.Y Samuel3-Sep-15 3:31
memberElijah O.Y Samuel3-Sep-15 3:31 
Questionprobleme"probleme d'envoi sms connexion terminée" Pin
Member 1188559320-Aug-15 2:59
memberMember 1188559320-Aug-15 2:59 
QuestionProbleme d'envoie sms Pin
Member 1188559319-Aug-15 2:51
memberMember 1188559319-Aug-15 2:51 
AnswerRe: Probleme d'envoie sms Pin
Member 124254429-May-16 1:57
memberMember 124254429-May-16 1:57 
GeneralRe: Probleme d'envoie sms Pin
OriginalGriff9-May-16 1:59
protectorOriginalGriff9-May-16 1:59 
GeneralMy vote of 5 Pin
rediffAM21-Jul-15 4:06
memberrediffAM21-Jul-15 4:06 
GeneralRe: My vote of 5 Pin
Fahad Rafiq30-May-16 19:54
memberFahad Rafiq30-May-16 19:54 
Questionfor bulk sms from mobile Pin
Member 1159693621-Jul-15 1:39
memberMember 1159693621-Jul-15 1:39 
QuestionHeloo Pin
shafee_s15-Jul-15 18:19
membershafee_s15-Jul-15 18:19 
AnswerRe: Heloo Pin
MuhammadUSman114-Aug-15 20:50
memberMuhammadUSman114-Aug-15 20:50 
QuestionTPLink MA180 USB Adapter Pin
Member 118232748-Jul-15 9:13
memberMember 118232748-Jul-15 9:13 
QuestionError Loading Excel File. Pin
Member 1179867228-Jun-15 16:59
memberMember 1179867228-Jun-15 16:59 
QuestionMessage Removed Pin
Member 1075791621-Apr-15 2:21
memberMember 1075791621-Apr-15 2:21 
QuestionKindly Check Worksheet Name Pin
Member 1156927331-Mar-15 0:19
memberMember 1156927331-Mar-15 0:19 
QuestionError Loading Excel FIle nKindly Check Worksheet Name Pin
oleinikbizon9-Mar-15 5:52
memberoleinikbizon9-Mar-15 5:52 
Question[My vote of 2] Get Port Com List couldn't detect Wavecom Modem Pin
aminvincent5-Mar-15 23:44
memberaminvincent5-Mar-15 23:44 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun18-Jan-15 21:07
memberHumayun Kabir Mamun18-Jan-15 21:07 
QuestionTested Mobile Model Names Pin
IT Criminal1-Dec-14 10:43
memberIT Criminal1-Dec-14 10:43 
AnswerRe: Tested Mobile Model Names Pin
Fahad Rafiq2-Dec-14 21:07
memberFahad Rafiq2-Dec-14 21:07 
AnswerRe: HELP ME Pin
Member 1242544224-May-16 3:53
memberMember 1242544224-May-16 3:53 
QuestionHOW Do i to make my Application delphi Auto detect My Modems by thier Card sim Service Provider ? Pin
bravesaw20-Nov-14 19:08
memberbravesaw20-Nov-14 19:08 
Questionerror Pin
Member 109682993-Nov-14 9:42
memberMember 109682993-Nov-14 9:42 
Questionhow to send long arabic sms? Pin
bakhoo3015-Oct-14 10:40
memberbakhoo3015-Oct-14 10:40 
Questionhow to read messages Pin
P Yulius Suwandi H12-Oct-14 3:02
memberP Yulius Suwandi H12-Oct-14 3:02 
AnswerRe: how to read messages Pin
Fahad Rafiq15-Oct-14 0:19
memberFahad Rafiq15-Oct-14 0:19 
QuestionJazakallah Pin
shaikh.quader10-Oct-14 9:56
membershaikh.quader10-Oct-14 9:56 
AnswerRe: Jazakallah Pin
Fahad Rafiq15-Oct-14 0:13
memberFahad Rafiq15-Oct-14 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 19 Aug 2013
Article Copyright 2012 by Fahad Rafiq
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid