Ask Your Question
2

How can I send messages to multiple phone numbers using Twilio SMS and .net?

asked 2021-06-08 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-01-02 09:00:00 +0000

nofretete gravatar image

To send messages to multiple phone numbers using Twilio SMS and .NET, you can create a loop that iterates through a list of phone numbers, and then calls the Twilio API for each phone number. Here's an example code snippet:

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Program
{
    static void Main(string[] args)
    {
        TwilioClient.Init("YOUR_ACCOUNT_SID", "YOUR_AUTH_TOKEN");

        // List of phone numbers to send SMS to
        var phoneNumbers = new string[] { "+1234567890", "+1112223333", "+4445556666" };

        // Loop through phone numbers and send SMS for each
        foreach (var phoneNumber in phoneNumbers)
        {
            var message = MessageResource.Create(
                body: "Hello from Twilio!",
                from: new Twilio.Types.PhoneNumber("YOUR_TWILIO_PHONE_NUMBER"),
                to: new Twilio.Types.PhoneNumber(phoneNumber)
            );

            Console.WriteLine($"SMS sent to {phoneNumber}");
        }
    }
}

In this example, we first initialize the Twilio client with our account SID and auth token. We then create an array of phone numbers to send SMS to.

We loop through each phone number and call the MessageResource.Create method to send an SMS message with the text "Hello from Twilio!" from our Twilio phone number to the current phone number in the loop.

Finally, we output a message indicating that the SMS was sent to each phone number.

Note that you'll need to replace YOUR_ACCOUNT_SID, YOUR_AUTH_TOKEN, and YOUR_TWILIO_PHONE_NUMBER with your own account information and Twilio phone number.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-08 11:00:00 +0000

Seen: 11 times

Last updated: Jan 02 '22