简体   繁体   中英

Sending SMS in C# using Twilio

I read all the other questions regarding this topic but none actually answers exactly my question. I installed twilio package. added it to the C# project. opened an account in twilio and had a number and so on. but it seems not working any ideas ? here's the code

using System;
using Twilio;

namespace Project_C_Sharp_Final
{
    public partial class User : Form
    {

 private void label4_Click(object sender, EventArgs e)
        {
            string AccountSid = "[i wrote the sid here]";
            string AuthToken = "[i wrote the authtoken here]";
          var twilio = new TwilioRestClient(AccountSid, AuthToken);
          var message = twilio.SendMessage("YOUR_TWILIO_NUMBER", "THE NUMBE I WANT TO SEND TO" , "Check New Offers");
       }
   }
}    

message is not being sent... did i write anything wrong ? did i miss anything ?

Before putting my solution, I want to re-iterate what philnash has mentioned. Testing Twilio Credentials will not actually send SMS.

If you are using test credendials then below solution will not work for you.

For error : Permission Not Enable for the region indicated by the to number, that means the country you are trying to send SMS to is not enabled in geolocation settigs of your Twilio account.

You need to loging to twilio portal and navigate to following URL. https://www.twilio.com/user/account/settings/international

Here you can enable/disable countries for both SMS and Voice Call. Check if the country you are trying to send SMS to is enabled in that page or not. If not you can enable it and try sending SMS again.

Thanks and regards, Chetan Ranpariya

Twilio developer evangelist here.

In the comments you say you're using the test credentials. Test credentials will not actually send any messages (or make calls) they are to make sure you're making the request correctly without costing you.

To make Twilio send messages you need to use the production credentials. If you are still on a trial account this won't cost you anything either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM