banner



How To Send Bulk Sms Using C# Windows Application

Chief Start-upwardly Screen
Primary Screen Of Bulk SMS Sender

Introduction
A simple SMS awarding using free GSM Advice Library GSMComm for sending majority SMS to multiple numbers of recipients using an Excel file for our all messages and recipients numbers
Groundwork

Very helpfull for learning ...How to send SMS through C# using free GSM Communication Library with minimal efforts :-)
Using the code

So now lets continue the actual code , First stride y'all demand to get connect your GSM Phone / GSM Modem to your PC , Assuming that y'all have connected your device to PC and all the nessacery drivers are loaded and it is Connected Successfully.

For connecting device using GSM Advice LIBRARY you have to download GSM COM LIb from http://www.scampers.org and reference it in your project , Then using it in your projection

  1. using GsmComm.GsmCommunication;
  2. using GsmComm.Interfaces;
  3. using GsmComm.PduConverter;
  4. using GsmComm.Server;

And construct the initial nessecary info for connection and GSMComm classe.

  1. public static Int16 Comm_Port = 0;
  2. public static Int32 Comm_BaudRate = 0;
  3. public static Int32 Comm_TimeOut = 0;
  4. public static GsmCommMain comm;

Bingo after connecting your device to your PC run the projection and above shown Main Screen will appears, Now press Become COM Port List push on main screen to go all Ports information in to the DataGrid

All the COM Port Listing in the Organisation volition announced in the Filigree Box every bit shown above

For Getting the COM Port List and boosted data of COM Ports , Mircosoft has provided us an Utility Called "WMI CODE CREATOR" Which can easily create C# lawmaking for that purpose Google It and download to your PC information technology will give you lot thousands Classes / Methods / Properties to go the system data with minimal efforts of system programming.

Hither how i get all the COM Port Data with all the addtional device information

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

  1. endeavor
  2. {
  3. ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_SerialPort");
  4. foreach (ManagementObject queryObj in searcher.Get())
  5. {
  6. if (queryObj != null)
  7. {
  8. object captionObj = queryObj["DESCRIPTION"];
  9. object capdeviceid = queryObj["DEVICEID"];
  10. object MaxBaudRate = queryObj["MAXBAUDRATE"];
  11. object connstatus = queryObj["STATUS"];
  12. string timeoutsec = "100";
  13. dataGridView3.Rows.Add together(capdeviceid, captionObj, MaxBaudRate, timeoutsec, connstatus);
  14. }}}

If without error you get all the COM Port Information from system then 2nd step is to connect to the device , Click on the Cell of Information Grid of your desired device to connect , Every bit shown beneath....A Confirmation message volition appear and Connected device information will likewise exist shown and DataGrid Cell will Highlighted Green.

How to Connect to GSM Device / Phone , Try GSMComm connectedness with the values getting from the DataGrid when Cell Clicked

  1. //FOR GsmCommMain we give 3 arguments (PORT , BAUD RATE , TIMEOUT SEC)
  2. Comm_Port =     Convert.ToInt16(dataGridView3.Rows[i].Cells[0].Value.ToString().Substring(3));
  3. Comm_BaudRate = Convert.ToInt32(dataGridView3.Rows[i].Cells[two].Value.ToString());
  4. Comm_TimeOut =  Convert.ToInt32(dataGridView3.Rows[i].Cells[3].Value.ToString());
  5. comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut);
  6. try
  7. {
  8. comm.Open();
  9. if (comm.IsConnected())
  10. {
  11. //Something to practise when device connected
  12. }
  13. Getting Phone Information after successfull connection
  14. //Getting telephone information through IdentificationInfo Structures of GSMComm ...
  15. try
  16. {
  17. Phone_Name.Text = comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
  18. Phone_Model.Text = comm.IdentifyDevice().Model.ToUpper().ToString();
  19. Revision_Num.Text = comm.IdentifyDevice().Revision.ToUpper().ToString();
  20. Serial_Num.Text = comm.IdentifyDevice().SerialNumber.ToUpper().ToString();
  21. }

After Successfully connecting with the Device ...Now it'southward time to send a word out there :-)

Lets Check Out Single SMS Sending TAB

  1. //For sending single SMS with minimal code
  2. //For SmsSubmitPdu we give three arguments (SMS TEXT , RECIPIENTS NUMBER , ENCODING )
  3. string CELL_Number, SMS_Message;
  4. SmsSubmitPdu pdu1;
  5. CELL_Number = Cell_Num.Text.ToString();
  6. SMS_Message = SMS_Text.Text.ToString();
  7. try
  8. {
  9. pdu1 = new SmsSubmitPdu(SMS_Message, CELL_Number, "");
  10. comm.SendMessage(pdu1);
  11. MessageBox.Show("M E South S A Yard E - S E Due north T", "Information", MessageBoxButtons.OK,
  12. MessageBoxIcon.Data);
  13. }

For sending multiple SMS from Excel file here'southward how yous can acheive this .....

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

As well y'all demand to rename your Excel sheet to SMS because information technology also checking that canvass name

  1. private void button3_Click_1(object sender, EventArgs e)
  2. {
  3. int rows_counting, column_counting1 = 0;
  4. OpenFileDialog dialog = new OpenFileDialog { };
  5. dialog.Filter = "SMS Sending File(*.xlsx;*.xls)|*.xlsx;*.xls";
  6. dialog.Championship = "Select Excel File For SMS";
  7. DialogResult dlgresult = dialog.ShowDialog();
  8. if (dlgresult == DialogResult.Cancel)
  9. {
  10. MessageBox.Prove("You Cancelled !!!");
  11. }
  12. else
  13. {
  14. string sms_filename = dialog.FileName;
  15. if (Arrangement.IO.File.Exists(sms_filename))
  16. {
  17. endeavor
  18. {
  19. Cursor.Current = Cursors.WaitCursor;
  20. cord connectionString = String.Format(
  21. @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};
  22. Extended Properties=""Excel viii.0;HDR=YES;IMEX=1;""",
  23. sms_filename);
  24. string query = String.Format("select * from [{0}$]", "SMS");
  25. OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
  26. dataSet = new DataSet();
  27. dataAdapter.Fill(dataSet);
  28. dataGridView1.DataSource = dataSet.Tables[0];
  29. dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
  30. rows_counting = dataGridView1.RowCount - 1;
  31. column_counting1 = dataGridView1.ColumnCount;
  32. if (column_counting1 < 2 || column_counting1 > ii)
  33. {
  34. MessageBox.Testify("Kindly Check Column Count in Excel Sail !!!\r\n\north
  35. There Should Exist Just Two Columns in Canvas Similar Below\r\n\northward
  36. CELL NUMBER | Bulletin", "Error", MessageBoxButtons.OK,
  37. MessageBoxIcon.Mistake);
  38. return;
  39. }
  40. if (    dataGridView1.Columns[0].Name.ToString().ToUpper() == "CELL NUMBER" &&
  41. dataGridView1.Columns[ane].Name.ToString().ToUpper() == "Messages")
  42. {
  43. label25.Text = "Total SMS In Excel File " + rows_counting;
  44. MessageBox.Bear witness("Data Imported Successfully...!!!\r\n\n
  45. Check Imported Values & SEND SMS.....!!!!",
  46. "Information", MessageBoxButtons.OK,
  47. MessageBoxIcon.Information);
  48. }
  49. else
  50. {
  51. MessageBox.Testify("Column Names Are Not In Specified Format !!!",
  52. "Error", MessageBoxButtons.OK,
  53. MessageBoxIcon.Error);
  54. render;
  55. }
  56. }
  57. take hold of (Exception E6)
  58. {
  59. MessageBox.Show("Error Loading Excel FIle\r\north\nKindly Check Worksheet Name",
  60. "Mistake", MessageBoxButtons.OK,
  61. MessageBoxIcon.Error);
  62. return;
  63. }
  64. }}}

After loading excel file in to the DataGrid nosotros'll merely utilize For Loop role to get Prison cell NUMBER & MESSAGE One By 1 and transport it using very simple code just similar for sending Unmarried SMS Message

  1. string MSMS_Number, MMessage;
  2. int i;
  3. SmsSubmitPdu pdu3;
  4. try
  5. {
  6. if (comm.IsConnected()==true)
  7. {
  8. try
  9. {
  10. for (i = 0; i < dataGridView1.RowCount - 1; i++)
  11. {
  12. MSMS_Number = dataGridView1.Rows[i].Cells[0].Value.ToString();
  13. MMessage = dataGridView1.Rows[i].Cells[1].Value.ToString();
  14. pdu3 = new SmsSubmitPdu(MMessage, MSMS_Number, "");
  15. comm.SendMessage(pdu3);
  16. //Sleeps system for 1000ms for refreshing GSM Modem / Telephone
  17. System.Threading.Thread.Sleep(m);
  18. }
  19. Cursor.Electric current = Cursors.Default;
  20. MessageBox.Bear witness("T O T A L - M Due east Due south S A G E - S E N T = " + i,
  21. "Information", MessageBoxButtons.OK,
  22. MessageBoxIcon.Information);
  23. }

Simple is'nt ....If non ship me a question i will be glad to help you out :-)

And for actress spice i have added unproblematic checking when Excel File is loaded in to DataGridView when CHECK VALUES push is clicked information technology volition bank check for NULL VALUES and Bulletin text more than than 160 Characters and highlighted cells to RED if found mistake else cells will exist greenish if establish no error....

For acheving prison cell checking a simple yet once again FOR LOOP will do the Magic ;-)

//On Check Values push button below code will check cell values One Past One and set the color either RED or GREEN
if IF Argument passes

  1. private void button7_Click(object sender, EventArgs e)
  2. {
  3. for (int i = 0; i < dataGridView1.RowCount - 1; i++)
  4. {
  5. for (int j = 0; j < dataGridView1.ColumnCount ; j++)
  6. {
  7. if (    dataGridView1.Rows[i].Cells[j].Value.ToString() == "" ||
  8. dataGridView1.Rows[i].Cells[j].Value.ToString().ToUpper() == "-" ||
  9. dataGridView1.Rows[i].Cells[j].Value.ToString().Length > 160 )
  10. //Setting Cellls Background color to RED if higher up Fault Constitute in Whatsoever of the cells
  11. dataGridView1.Rows[i].Cells[j].Manner.BackColor = Colour.Ruby-red;
  12. //Setting Cells Background color to Greenish which passes above validations
  13. else
  14. dataGridView1.Rows[i].Cells[j].Way.BackColor = Color.Green;
  15. button4.Enabled = true;
  16. }}}

Thats All Folks ......Happy Coding.........Let The SMS Brainstorm !!! :-)

Points of Interest

Yous Should Endeavour WMI Code CREATOR It Will Requite Lots Of Assistance To Explore System Information

History
This is Actually a much smaller version of lawmaking made for a much larger projection for some specific purpose for sending Majority SMS for fellow Team Members :-)

Would exist glad if you like to have any help...

Bulk SMS SENDER Ver ane.0

Source: https://bytes.com/topic/c-sharp/insights/931771-bulk-sms-sender-c

Posted by: goodingpold1960.blogspot.com

0 Response to "How To Send Bulk Sms Using C# Windows Application"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel