Send SMS using Twilio REST API


Here are some helpful notes for send sms using Twilio sms API.
First you should have account on http://twilio.com/
After creating a account Go to your visual studio and
install twilio package from Nuget package manager.
Use this code to send SMS,


protected Twilio.SMSMessage SendSMS()
{
string AccountSid = "your Sid get from https://www.twilio.com/user/account/settings";
string AuthToken = "get token from https://www.twilio.com/user/account/settings";
var twilio = new TwilioRestClient(AccountSid, AuthToken);

var message = twilio.SendSmsMessage("<strong>sender num</strong>", "<strong>reciever number</strong>", "<strong>your message body here</strong>");
//Note :: sender number you will get from here https://www.twilio.com/user/account/phone-numbers/incoming
try
{
if (message != null)
{
lblMessage.Text = message.Status;
if (message.Sid != null)
{
lblMessage.Text = lblMessage.Text + " SID: " + message.Sid;
}
else
{
lblMessage.Text = "Error";
}
}
else
{
throw new Exception("Error");
}
}
catch (Exception e)
{
lblMessage.Text = e.Message.ToString();
}
return message;
}

You will get status and SID of message.
you will get more info about API from https://www.twilio.com/docs

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: