Sample Visual Basic Code for Sending SMS


You can also Download the full source code!


  1. Function send_sms()
  2. Dim phone_number = "phone number to message"
  3. Dim sender_id = " sender id"
  4. Dim message = "message to send"
  5. Dim reader As StreamReader
  6. Dim request As WebRequest
  7. Dim response As WebResponse
  8. Dim data As String = ""
  9. Dim api_key = "xxxxxxxxxxxxxxx"
  10. Dim
  11. Try
  12. request = WebRequest.Create("http://sms.nasaramobile.com/api?api_key=" + api_key + "&&sender_id=" + sender_id + "&&phone=" + phone_number + "&&message=" + message)
  13. request.Timeout = 30000
  14. response = request.GetResponse()
  15. reader = New StreamReader(response.GetResponseStream())
  16. data = reader.ReadToEnd()
  17. If data = 1801 Then
  18. MessageBox.Show("message sent successfully")
  19. ElseIf data = 1802 Then
  20. MessageBox.Show("message sending failed")
  21. ElseIf data = 1803 Then
  22. MessageBox.Show("invalid login phone or password given")
  23. ElseIf data = 1804 Then
  24. MessageBox.Show("you do not have enough sms credit to send message")
  25. ElseIf data = 1805 Then
  26. MessageBox.Show("sender id must be more than 1 charater and less than 12 characters")
  27. ElseIf data = 1806 Then
  28. MessageBox.Show("you do not have enough sms credit to send message")
  29. Else
  30. MessageBox.Show("phone number must be more than 8 characters")
  31. End If
  32. Catch ex As Exception
  33. MsgBox(ex.Message)
  34. End Try
  35. End Function