0

I need to know how do I send a bulk SMS using Twilio API and C#.I did some research which also show that I need to use Twilio’s Passthrough API, but I fail to understand it. Here is the code I compiled:

const string accountSid = "xxxxx";
const string authToken = "xxxxx";

TwilioClient.Init(accountSid, authToken);

MessageResource.Create(to: new PhoneNumber("+27" + txtTo.Text),
                       from: new PhoneNumber("xxxxx"),
                       body: txtMessage.Text,
                       provideFeedback: true,
                       statusCallback: new Uri("http://requestb.in/1234abcd"));

MessageBox.Show("Message sent successfully");
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Marcus
  • 47
  • 2
  • 12

1 Answers1

2

You can't do this way. You have to loop through your subscribers list and send it one by one or by using a parallel foreach:

var subscriber = new Dictionary<string, string>() {
            {"+3912345678", "John"},
            {"+3917564237", "Mark"},
            {"+3915765311", "Ester"}
        };

// Iterate over subscribers
foreach (var person in subscriber)
{
    // Send a new outgoing SMS by POSTing to the Messages resource
    MessageResource.Create(
        from: new PhoneNumber("555-555-5555"), // From number, must be an SMS-enabled Twilio number
        to: new PhoneNumber(person.Key), // To number, if using Sandbox see note above
        // Message content
        body: $"Hello {person.Value}");

    Console.WriteLine($"Sent message to {person.Value}");
} 
Giox
  • 4,785
  • 8
  • 38
  • 81
  • How could I make the Dictionary list to be on one textbox and be able to send multiple numbers using one textbox – Marcus Apr 22 '18 at 14:50
  • @Marcus insert comma or ; separetes values in the textbox then use one or more split () to get an array to insert in the dictionary. Like John Doe: +001212456789; first split (';') to get rows then a second split(':') on each row to get name and number. – Giox Apr 22 '18 at 14:58