Have you ever wanted to programmatically send an SMS? Who cares, this technology is no longer important. But if yous till need to do so here’s how you can do this with Ionic Framework and Cordova.

Note: If this tutorial was helpful, need further clarification, something is not working or do you have a request for another Ionic post? Furthermore, if you don't like something about this blog, if something is bugging you, don't like how I'm doing stuff here, again leave me a comment below. I'm here to help you, I expect the same from you. Feel free to comment below, subscribe to my blog, mail me to dragan.gaic@gmail.com, or follow and mention me on twitter (@gajotres). Thanks and have a nice day!

PS. If you want my help, if possible (even if it takes you some time to do that), create a working example I can play with. Use Plunker for AngularJS based questions or jsFiddle for jQuery/jQuery Mobile based questions.


Table of Contents

Click here if you want to see other tutorials, or articles about the Ionic framework (themes, templates, plugins, tutorials)


Make sure you have these requirements:
  • Android Environment (or iOS if your working on a MacOS)
  • nodeJS
  • Ionic
  • Cordova
If you don’t have a previous Ionic Framework experience you can find more information here: Ionic Framework | Installation Guide.

1. Update Ionic & Cordova

The latest nodeJs version is a top priority, you can’t download/update proper Ionic Framework version without it.
After nodeJS, update Ionic, and Cordova, older versions may not work with this tutorial:
npm update -g cordova ionic

2. Create a New Project

ionic start IonicSendSMSDemo blank
cd IonicSendSMSDemo
Warning: Since some of you never worked with Ionic CLI. From this point and further, every time I tell you to execute something, do that inside a project folder.
Android platform is required for this example:
ionic platform add android
MacOS users can also add iOS platform:
ionic platform add ios

3. Download ngCordova archive

ngCordova is a collection of 63+ AngularJS extensions on top of the Cordova API that make it easy to build, test, and deploy Cordova mobile apps with AngularJS. While we can make this work without ngCordova, it’s much more practical this way. This collection also holds many Ionic Framework compatible plugins.
Download ngCordova zip file, here’s site link:
Official Site Docs Download Link
Unzip this archive, find a file name called: ng-cordova.min.js, it should be available at this location: ng-cordova-master\dist\.
Open your newly created project directory and copy ng-cordova.min.js to this location: IonicSendSMSDemo\www\js.
Now include this location to index.html located at IonicSendSMSDemo\www; add it above cordova.js file, like this:
<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

4. Install Cordova SMS plugin

Next line will import and install necessary plugins into newly created project:
cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
cordova plugin add cordova-plugin-whitelist
If you’re using Cordova 5.0.0 you will already have preinstalled Whitelist plugin.
We also need Cordova File plugin so we can access device file system.
GitHub - SMS GitHub - Whitelist


At this point, you should have everything set up and ready, we can start working on our example.
Go to IonicSendSMSDemo project directory and find app.js, alter angular.module line and include ngCordova service, like this:
var app = angular.module('starter', ['ionic', 'ngCordova'])
Open index.html file, add a controller to ion-content directive:
      <ion-header-bar class="bar-stable">
        <h1 class="title">SMS Example</h1>
      <ion-content ng-controller="SMSController">
Initialize this controller in app.js file; don’t forget to inject $cordovaSms service, like this:
app.controller('SMSController', function($scope, $cordovaSms) {

Now we need to initialize Whitelist plugin; add this meta tag to index.html HEAD content:
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">
We will use next function to send an SMS, don’t forget to wrap it into Cordova deviceready event (or Ionic ready depending on your project):
  document.addEventListener("deviceready", function() {

    var options = {
      replaceLineBreaks: false, // true to replace \n by a new line, false by default
      android: {
        intent: '' // send SMS with the native android SMS messaging
          //intent: '' // send SMS without open any other app
          //intent: 'INTENT' // send SMS inside a default SMS app

    $scope.sendSMS = function() {

        .send('0959052082', 'This is some dummy text', options)
        .then(function() {
          // Success! SMS was sent
        }, function(error) {
          // An error occurred
options object is important here. The first parameter (replaceLineBreaks) is boolean which defines should message use a “\n” or not, false is a default one. The second parameter defines if our application should send SMS directly or via default SMS application. If default application is selected then you will need to manually press Send button. Both parameters are described in example comments.
Continue Reading

  • Preetzz Singh

    How to send SMS on emulator ?!?!?

    • You can’t, an emulator is not a real device. To be able to send an SMS, a device must be connected to some mobile network provider.

      But you can receive a SMS, through emulation.

  • “Who cares, this technology is no longer important.” -> In France, we care cause SMS and MMS are unlimited 😉

  • Jomar Palmes

    Hi do you also have this one with a database? I mean, the sent and received messages would be save on a database locally or hosted? Thank you !

  • Gobezu Sewu

    Is just starting on my ionic adventure. Thanks a lot for such valuable resource. Would love to see how you tackle accessing incoming SMS.

  • Chong

    HI, beside IOS, do you have any sending sms example for android?

    • This is an Android example, if you wish I can upload it to GitHub.

  • Chris Mellow

    I copied everything literally after it didnt work the first time i just copied and pasted. I can type in a number and a message but when i click send nothing happens just the keyboard disappears

    • Chris Mellow

      nevermind got it working :}

      • Danish Fayaz

        What did you do? How you got it to work?

  • I’ve copied and followed all, it works! but it only send the message defined in the code “This is some dummy text”. And same with the number, I have altered it with sms.message variable but it gives me an error. How to send my own message to any other required number please.

    • Replace number and sms text with scope variables.

      • Thanks dear I have solved that problem just after posted this comment 🙂

  • Shu Xian

    Hi, gajs this is great tutorial. However, why i cannot send message if i leave intent options into nothing ? i only can send msg if i use INTENT options. Could it be whitelist problem? thanks best regard

    • From what I can see intent parameter is required. Worst case scenario it should be empty:

      intent: ” // send SMS without open any other app
      intent: ‘INTENT’ // send SMS inside a default SMS app

  • Chris Kawahito

    Thanks, just sent my first Ionic text to myself. Too bad you are having to support JQuery Mobile.

    • What do you mean by “to support jQuery Mobile”?

      • Chris Kawahito

        My experiences with JQuery MobileMobile has been pretty miserable. Ionic is so elegant, beautiful and a delight to work with by comparison. For webpages Bootstrap and Foundation are better options.. so I don’t see the point of jqm.. They haven’t updated since 2014..

        • I completely agree with you, you couldn’t have said it better. But I’m still covering jQuery Mobile since it still has a large user base (don’t know why) plus jQuery Mobile 1.5 beta will come in 2-3 weeks, unless they postpone it again.

          • Chris Kawahito

            Cool man, cheers! Playing with Ionic!

  • Mardi anto

    Can you help me, for a more complete tutorial on incoming sms ?

  • Mahesh Kulkarni

    When I run this application on my device it display an error that unfortunately app has stopped.Tell me what to do.

  • Daniel Sifontes

    well i try to do it! but don’t happen nothing! i don’t why! not error, not send! nothing !

  • Domenico Carbone

    Hi, great tutorial!
    There is a way to send sms in iOS without open Message app?

  • Amadu Abdul

    Great Article. Has significantly reduced my project completion time. Thanks a lot.
    Just one small thing, it seems the spelling of Cordova in the heading is not right.

  • Dan

    Hi, great article. When you said that SMS technology was no longer important, what did you mean by that? Is there a good alternative? I need to send an initial link to phone users, is there an alternative to SMS?

  • meiran

    Hi there!
    Can anyone help me solving this issue?

    I keep getting:
    ‘SyntaxError: Unexpected token’

    On the browser I see this:

    cordova.js:1487 GET file:///C:/Program%20Files/nodejs/IonicSendSMSDemo/www/cordova_plugins.js net::ERR_FILE_NOT_FOUNDexports.injectScript @ cordova.js:1487injectIfNecessary @ cordova.js:1495exports.load @ cordova.js:1575(anonymous function) @ cordova.js:1225

    app.js:12 Uncaught TypeError: Cannot read property ‘Keyboard’ of undefined(anonymous function) @ app.js:12(anonymous function) @ ionic.bundle.js:56230onPlatformReady @ ionic.bundle.js:2496Channel.fire @ cordova.js:760(anonymous function) @ cordova.js:223

    2ionic.bundle.js:26794 ReferenceError: sms is not defined

    at Object.send (ng-cordova.min.js:9)

    at Scope.$scope.sendSMS (app.js:41)

    at fn (eval at (ionic.bundle.js:27638), :4:212)

    at ionic.bundle.js:65427

    at Scope.$eval (ionic.bundle.js:30395)

    at Scope.$apply (ionic.bundle.js:30495)

    at HTMLButtonElement. (ionic.bundle.js:65426)

    at defaultHandlerWrapper (ionic.bundle.js:16787)

    at HTMLButtonElement.eventHandler (ionic.bundle.js:16775)

    at triggerMouseEvent (ionic.bundle.js:2953)(anonymous function) @ ionic.bundle.js:26794(anonymous function) @ ionic.bundle.js:23507Scope.$apply @ ionic.bundle.js:30500(anonymous function) @ ionic.bundle.js:65426defaultHandlerWrapper @ ionic.bundle.js:16787eventHandler @ ionic.bundle.js:16775triggerMouseEvent @ ionic.bundle.js:2953tapClick @ ionic.bundle.js:2942tapMouseUp @ ionic.bundle.js:3018

    help anyone??

    • It looks like plugin was not installed successfully.

    • Abhi Kureshi

      please go “lib” and copy bundle.js and paste to index file. hope you can solve this problem

  • Ridho M

    very assist me, thanks a lot..
    I have one question, is it possible to send SMS without record the message on the sender phone?

    I have one mobile app where the users register by Legal ID number. Then the admin will input their both ID & phone number to the form register. App will generate PIN number and send to users phone number. My concerns, I check on the admin phone device it will record the SMS outbox/sent. While the content is the PIN of the users, I mean it is secret content.

    Is there other trick if we can remove SMS after sent? How to get SMS status if they are pending or have sent?

    I have used gammu previously to build SMS gateway, and it has great feature for us to manage SMS. But it is not useful for the App, because we need to build third dedicated server.

  • Erandaka anupama

    Code works perfectly fine.Can I send the same sms to multiple users?

    • To be honest I don’t know, I never tryied it.

  • Vilas Soni

    undefined error in ionic.bundle.js (” sms is not defined “) in e
    $apply: function(expr) {
    try {
    try {
    return this.$eval(expr);
    } finally {
    } catch (e) {
    } finally {

    please help

  • lina

    Does SMSs can be recieved on a device with a lower version of android ?

  • disqus_j3uT35dkMq

    Hi! Can these codes work with iOS phones?

  • Danish Fayaz

    Guys, I’ve tried, used all the same code, still when I hit the send button. Nothing happens. Any guess?

  • Carlos Mortiga

    Working perfectly in Lollipop. Any reasons why it doesn’t work in Marshmallow? Please advice if there’s tweaking that needs to be done please…