send a twilio message in csharp

To send an SMS message via Twilio in C#, you can use the Twilio REST API and the Twilio NuGet package. Here's an example of how to do it:

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

class Program
{
    static void Main(string[] args)
    {
        // Your Account SID and Auth Token from twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var message = MessageResource.Create(
            body: "Hello, world!",
            from: new Twilio.Types.PhoneNumber("+1415XXXXXXX"),
            to: new Twilio.Types.PhoneNumber("+1555XXXXXXX")
        );

        Console.WriteLine(message.Sid);
    }
}
632 chars
23 lines

Replace the accountSid and authToken variables with your Twilio account SID and auth token, respectively. Then update the from and to phone numbers with the relevant phone numbers.

This code creates a new MessageResource with the Create method, passing in the body, from, and to parameters. Once the message is sent, the created MessageResource object will contain a Sid property, which can be used to track the status of the message.

gistlibby LogSnag