Introduction
Twilio is one of the popular and prominent cloud communications providers, providing a rich API that allows developers to effortlessly send and receive SMS texts, among other communication features. Using Twilio is quite easy as well as integrating it into the project. If you are new to Twilio, you can read my previous article, How To Integrate Twilio In C# .NET MVC Project To Send SMS? to integrate Twilio into your project.
In this article, we will see how to resolve the Twilio Exception: Permission to send an SMS has not been enabled for the region indicated by the 'To' number.
Cause of the exception
Before solving the exception, it is very important to find the reason why it occurred. So, there are some geographical permissions that Twilio enforces in their services and that restricts us developers, from using it in any country or region randomly without thinking about the risks. And by default, Twilio doesn't allow you to send SMS, or WhatsApp messages or use its services in any region as there is some region that involves high risks of fraudulent activity. Hence, we get the cause of this exception.
How to resolve the "Permission to send an SMS has not been enabled for the region indicated by the 'To' number" Exception in Twilio
Now that we know why this exception occurs, let's see how to resolve this-
Step 1. Log in and go to the Twilio dashboard.
Step 2. In the right side corner, you will see a search option, in the search bar, enter "geo", and you will get a dropdown, with a list of options.
Step 3. Since we are solving this exception for SMS, click on "SMS geographic permissions".
Step 4. A new page "Messaging Geographic Permissions" will open having many countries as options.
Step 5. Now, select the countries in which you want to send messages.
Step 6. Click, the "Save geo permissions" button.
Step 7. A popup will open for confirmation, click the "Update geo permissions" button.
Your changes will be saved and now you will not get the exception.
If you are still facing this issue, chances are that there are some other issues, and you should contact Twilio Support for further assistance.
Conclusion
Resolving the "Permission to send an SMS has not been enabled for the region indicated by the 'To' number" exception in Twilio involves adjusting messaging geographic permissions within the Twilio dashboard. By specifying the desired countries for SMS communication, developers can overcome this restriction and ensure seamless message delivery across regions, enhancing the reliability and effectiveness of Twilio integration in projects.