3
votes

I'm trying to send sms from Twilio in ASP .NET but it throws this:

The From phone number +XXXXXX is not a valid, SMS-capable inbound phone number or short code for your account

My code looks like this:

[HttpPost]
[Route("sms")]
public HttpResponseMessage SendMessage()
{
    var AccountSid = "XXXXXXXXXXXX";
    var AccountToken = "XXXXXXXXXXXX";
    TwilioClient.Init(AccountSid, AccountToken);
    var to = new PhoneNumber("+XXXXXXXXX");
    var from = new PhoneNumber("+XXXXXXXXXX");
    var message = MessageResource.Create(to: to, from: from, body: "Hi from me");
    return Request.CreateResponse(HttpStatusCode.OK,message.Sid);

}

My error looks like this:

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "The From phone number +XXXXXX is not a valid, SMS-capable inbound phone number or short code for your account.",
  "ExceptionType": "Twilio.Exceptions.ApiException",
}
2
Change var from = new PhoneNumber("+XXXXXXXXXX"); to var from = new PhoneNumber("+YYYYYYYYYY"); where +YYYYYYYYYY is a number you purchased from Twilio.Alex Baban
@AlexBaban i have used the trial number from twilio. Does the trial number does't work ? I am confused...Y B
There seems to be some problem in Twilio account configuration. Make sure you followed all steps on [tutorial]() and enabled permissions for your country code ]Djordje
While in trial mode, you can only send messages to non-Twilio phone numbers you've verified with Twilio. twilio.com/docs/usage/tutorials/…Alex Baban
@AlexBaban i have used trial number of usa in "from" and in "to" i have used the verified number . The "to" number is showing in my twilio verified number console.Y B

2 Answers

0
votes

As per Twilio, trial accounts are not able to send messages. they are simply there to test that you are making your API requests properly. Also, as per this, you can only workt with specific numbers and with few endpoints.

0
votes

I was using test credentials from twilio that is why that error was throwing but when i used live credentials, the error has gone and message has been successfully sent.