Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I want to send bulk sms using usb modem.I like to load numbers to textbox and and then send to all numbers.I coded to send single sms at a time.Main thing is to send bulk sms.
I need to remove white spaces and select numbers separately and send send same sms to all of them.

This is the code I wrote to send single sms mobno,msg are text boxes:
C#
private void button1_Click(object sender, EventArgs e)
{
    try {

        SmsSubmitPdu pdu;
        byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
        pdu = new SmsSubmitPdu(msg.Text, mobno.Text, dcs);
        int times = 1;
        for (int i = 0; i < times; i++)
        {
            comm.SendMessage(pdu);
        }

        MessageBox.Show("Message sent sucessfully");
    } catch (Exception ex) {
        MessageBox.Show("Modem not avaliable");
    }


}

here is my modem loading concept:

C#
      private GsmCommMain comm;
     private delegate void SetTextCallback(string text);
     private SmsServer smsServer;

     TextBox txtmsg = new TextBox();
     TextBox txtno = new TextBox();


     private void button3_Click(object sender, EventArgs e)
     {
         if (comboBox1.Text == "")
         {
             MessageBox.Show("Invalied Port Name");
             return;
         }
         comm = new GsmCommMain(comboBox1.Text, 9600, 150);
         Cursor.Current = Cursors.Default;
         bool retry;
         do
         {
             retry = false;
             try
             {
                 Cursor.Current = Cursors.WaitCursor;
                 comm.Open();
                 Cursor.Current = Cursors.Default;
                 MessageBox.Show("Connect Successfully");
             }
             catch (Exception)
             {
                 Cursor.Current = Cursors.Default;
                 if (MessageBox.Show(this, "Modem not available", "Check", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) retry = true;
                 { return; }
             }
         } while (retry);
     }

     private void sms_Load(object sender, EventArgs e)
     {
         comboBox1.Items.Add("Com1");
         comboBox1.Items.Add("Com2");
         comboBox1.Items.Add("Com3");
         comboBox1.Items.Add("Com4");
         comboBox2.Items.Add("Com1");
         comboBox2.Items.Add("Com2");
         comboBox2.Items.Add("Com3");
         comboBox2.Items.Add("Com4");

}
Posted
Updated 13-Jan-16 23:07pm
v2
Comments
OriginalGriff 14-Jan-16 4:10am    
And?
What is the problem?
Afzaal Ahmad Zeeshan 14-Jan-16 5:36am    
Bulk SMS is the problem. :laugh:
OriginalGriff 14-Jan-16 5:40am    
:laugh:
Does sound like he wants to be a spammer, doesn't it?
But there may be a legitimate reason. Doubtful, but possible!
tharukanc 14-Jan-16 6:28am    
not be a spammer man!making a database program for a company they said they want to send sms to their employees
OriginalGriff 14-Jan-16 6:37am    
So what is the problem?
Where are you stuck?

Why are you using a modem? If you're trying to perform SMS on the cheap, search email to text - Google Search[^]. Basically send an email to a SMS gateway that consists of <phonenumber>@<emailgateway>. Each major cell provider has one of these. The major drawback is not being able to receive replies.

Or if you're preforming the work for a company like you suggest, then they should be able to put a little money towards the project. Companies like Twilio - APIs for Text Messaging, VoIP & Voice in the Cloud[^] provide amazing .NET APIs for sending and receiving SMS messages along with multi-media messages.

I don't work for Twilio, but I use their SMS service for a website I run and it is amazing and cheap enough for a personal project.

Hogan
 
Share this answer
 
Try this.

mono.Text should contains all numbers with whitespace separation.


C#
private void button1_Click(object sender, EventArgs e)
{
    try {
          foreach(string varMobNo in mono.Text.split(' '))
           {
 
            SmsSubmitPdu pdu;
            byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
            pdu = new SmsSubmitPdu(msg.Text, varMobNo , dcs);
            int times = 1;
            for (int i = 0; i < times; i++)
            {
              comm.SendMessage(pdu);
            }
            }
        MessageBox.Show("Message sent sucessfully");
    } catch (Exception ex) {
        MessageBox.Show("Modem not avaliable");
    }
 

}
 
Share this answer
 
Comments
tharukanc 17-Jan-16 11:51am    
this works buddy thanks for helping
"How is the textbox organised?
Is it multiline and the numbers each on separate lines, or is are they separated by semicolons, or what?"

tharukanc 22 mins ago
"for each line one number"


Then they are already separated: a multiline TextBox has a Lines property which returns each separate line as a single string within an array:
C#
string[] numbers = myTextBox.Lines;

You can use a simple foreach loop to process each of them, and removing spaces for each is trivial:
C#
foreach (string line in numbers)
   {
   string number = line.Replace(" ", "");
   ... send SMS to number using your working code.
   }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900