Home > Software engineering >  Unable to send SMS using twilio in C#
Unable to send SMS using twilio in C#

Time:05-27

I tried to send SMS using the sample code from the twilio website but I am getting an error "Invalid TLS protocol". I had used valid accountsid, authtoken and verified mobile numbers.

class Program
{
    static void Main(string[] args)
    {
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var message = MessageResource.Create(
            body: "Hi there",
            from: new Twilio.Types.PhoneNumber(" 15017122661"),
            to: new Twilio.Types.PhoneNumber(" 15558675310")
        );

        Console.WriteLine(message.Sid);
    }
}

Thanks, Mohan

CodePudding user response:

Apparantly by adding this line to code before sending request it fixed. To see more information go to related issue in this link:

Http Client for https endpoint

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  • Related