2
Answers

how to send bulk sms in batches of 100 sms using loop

Rahul Sharma

Rahul Sharma

7y
109
1
I want to send bulk sms(numbers are not fixed) to numbers from database but sms provider is allowing only 100 sms at a time, how to send bulk SMS  using loop. plz if possible provideme the code.
Answers (2)
0
Rahul Sharma

Rahul Sharma

NA 33 994 7y
Sagar Pandurang Kap How to achieve this result without LINQ
0
Sagar  Pandurang Kap

Sagar Pandurang Kap

NA 2.7k 7.5k 7y
Hi,
 
Regarding Grouping Your Messages
 
Assuming that the numbers you are planning on sending to are housed in a database, you should be able to get a collection of the 1000 numbers that you are planning on sending to and simply grabbing 100 number sections at a time though LINQ :
 
// Grab your List of numbers to send to
var recipients = ExampleContext.Users.Select(x => x.MobileNumber).ToList();
// Store the batches to process
var batchesToProcess = numbers.Count() / 100;
// Loop through your numbers (100 at a time)
for(int i = 0; i <= batchesToProcess; i++)
{
// Output your first batch (of 100 numbers)
var batch = numbers.Skip(i * 100).Take(100);
// Send to each in this batch
foreach(var number in batch)
{
// Code to send SMS message here
}
// Consider placing a delay between each batch here
Thread.Sleep(6000);
}
 
Hope it helps...