<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ sms - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ sms - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 26 Jul 2026 22:34:40 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/sms/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to send an SMS in Node.js via SMPP Gateway ]]>
                </title>
                <description>
                    <![CDATA[ By Shailesh Shekhawat Introduction SMPP (Short Message Peer-to-Peer) is a protocol used by the telecommunications industry. It exchanges SMS messages between (SMSC) and ESME. SMSC acts as middleman to store the message and route it. ESME is the syste... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-send-an-sms-in-node-js-via-smpp-gateway-9c7b12e4600a/</link>
                <guid isPermaLink="false">66d461563bc3ab877dae2247</guid>
                
                    <category>
                        <![CDATA[ communication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ sms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 01 Oct 2018 21:13:25 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*XVSMVkKMUtd0tX_DzlhVbA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Shailesh Shekhawat</p>
<h3 id="heading-introduction">Introduction</h3>
<p>SMPP (Short Message Peer-to-Peer) is a protocol used by the telecommunications industry. It exchanges SMS messages between (SMSC) and ESME. SMSC acts as middleman to store the message and route it. ESME is the system that delivers SMS to SMSC.</p>
<p>This tutorial will help you to send SMS messages using your own SMSC gateway.</p>
<h3 id="heading-getting-started"><strong>Getting Started</strong></h3>
<h4 id="heading-where-is-smpp-used"><strong>Where is SMPP used?</strong></h4>
<p>SMPP is particularly suited to high-volume and high-throughput SMS applications. It has the following features:</p>
<ul>
<li>Connections established by the client with the server are persistent and may be kept open indefinitely. There is not the connection overhead to be found with protocols such as HTTP that use transient connections.</li>
<li>Requests can be issued by the SMPP client as well as the SMPP server.</li>
<li>Requests are processed asynchronously. Meaning that requests can be issued without having to wait first for responses to earlier requests to be received.</li>
</ul>
<h4 id="heading-how-to-use-it"><strong>How to use it</strong></h4>
<p>We will be using Node.js <a target="_blank" href="https://github.com/farhadi/node-smpp">node-smpp</a> for the implementation.</p>
<p>SMPP Requests:</p>
<ul>
<li><strong>bind</strong> request to establish the SMPP session</li>
<li><strong>submit_sm</strong> requests issued by the client to send messages to a mobile phone</li>
<li><strong>deliver_sm</strong> requests issued by the server to forward messages from the mobile phone to the client, including delivery receipts</li>
<li><strong>enquire_link</strong> requests issued by both the server and client to keep the SMPP session alive</li>
<li><strong>unbind</strong> request issued by either the server or the client to terminate the SMPP session</li>
</ul>
<h4 id="heading-how-it-works"><strong>How it works</strong></h4>
<p>An SMPP session must be established between the ESME (External Short Messaging Entities) and the Message Centre or SMPP Routing Entity where appropriate.</p>
<p>This session is created using an SMPP client that communicates with an SMPP protocol. There is a continuous exchange of SMPP PDU (Protocol Data Units or Packets) to ensure a proper bind/connection is established.</p>
<p>The SMPP client takes care of the SMS and delivers them to the SMPP server. The SMPP server also transmits a <strong>delivery report</strong> back to the client when there is a change of status for an SMS.</p>
<p>Node.js will help us to achieve high MPS as it performs all I/O operations asynchronously.</p>
<p>Traditionally, I/O operations either run synchronously (blocking) or asynchronously by spawning off parallel threads to perform the work.</p>
<p>This old approach consumes a lot of memory and is notoriously difficult to program.</p>
<p>In contrast, when a Node application needs to perform an I/O operation, it sends an asynchronous task to the event loop, along with a callback function. It then continues to execute the rest of its program.</p>
<p>When the async operation completes, the event loop returns to the task to execute its callback.</p>
<h4 id="heading-store-and-forward-message-mode"><strong>Store and Forward Message Mode</strong></h4>
<p>The conventional approach to SMS has been to store the message in an SMSC storage area (e.g. message database) before forwarding the message for delivery to the recipient SME. With this model, the message remains securely stored until all delivery attempts have been made by the SMSC. This mode of messaging is commonly referred to as “store and forward”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/l2qlTM5I7RaqA3ipp3oE-2PZR7zaXh5WZR7S" alt="Image" width="800" height="886" loading="lazy"></p>
<h3 id="heading-step-1-create-smpp-session">Step 1: Create SMPP Session</h3>
<p>In beginning, we need to create a new <code>smpp</code> session with IP address and port.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> smpp = <span class="hljs-built_in">require</span>(<span class="hljs-string">'smpp'</span>);
<span class="hljs-keyword">const</span> session = <span class="hljs-keyword">new</span> smpp.Session({<span class="hljs-attr">host</span>: <span class="hljs-string">'0.0.0.0'</span>, <span class="hljs-attr">port</span>: <span class="hljs-number">9500</span>});
</code></pre>
<h3 id="heading-step-2-bind-transceiver">Step 2: Bind Transceiver</h3>
<p>As soon as it connects we will bind it on <code>connect</code> event:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> isConnected = <span class="hljs-literal">false</span>
session.on(<span class="hljs-string">'connect'</span>, <span class="hljs-function">() =&gt;</span> {
  isConnected = <span class="hljs-literal">true</span>;

  session.bind_transceiver({
      <span class="hljs-attr">system_id</span>: <span class="hljs-string">'USER_NAME'</span>,
      <span class="hljs-attr">password</span>: <span class="hljs-string">'USER_PASSWORD'</span>,
      <span class="hljs-attr">interface_version</span>: <span class="hljs-number">1</span>,
      <span class="hljs-attr">system_type</span>: <span class="hljs-string">'380666000600'</span>,
      <span class="hljs-attr">address_range</span>: <span class="hljs-string">'+380666000600'</span>,
      <span class="hljs-attr">addr_ton</span>: <span class="hljs-number">1</span>,
      <span class="hljs-attr">addr_npi</span>: <span class="hljs-number">1</span>,
  }, <span class="hljs-function">(<span class="hljs-params">pdu</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (pdu.command_status == <span class="hljs-number">0</span>) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Successfully bound'</span>)
    }

  })
})

session.on(<span class="hljs-string">'close'</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'smpp is now disconnected'</span>) 

  <span class="hljs-keyword">if</span> (isConnected) {        
    session.connect();    <span class="hljs-comment">//reconnect again</span>
  }
})

session.on(<span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> { 
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'smpp error'</span>, error)   
  isConnected = <span class="hljs-literal">false</span>;
});
</code></pre>
<h3 id="heading-step-3-send-sms">Step 3: Send SMS</h3>
<p>So now we are connected, let's send the SMS:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sendSMS</span>(<span class="hljs-params">from, to, text</span>) </span>{
   <span class="hljs-keyword">from</span> = <span class="hljs-string">`+<span class="hljs-subst">${<span class="hljs-keyword">from</span>}</span>`</span>  

<span class="hljs-comment">// this is very important so make sure you have included + sign before ISD code to send sms</span>

   to = <span class="hljs-string">`+<span class="hljs-subst">${to}</span>`</span>

  session.submit_sm({
      <span class="hljs-attr">source_addr</span>:      <span class="hljs-keyword">from</span>,
      <span class="hljs-attr">destination_addr</span>: to,
      <span class="hljs-attr">short_message</span>:    text
  }, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">pdu</span>) </span>{
      <span class="hljs-keyword">if</span> (pdu.command_status == <span class="hljs-number">0</span>) {
          <span class="hljs-comment">// Message successfully sent</span>
          <span class="hljs-built_in">console</span>.log(pdu.message_id);
      }
  });
}
</code></pre>
<p>Now after sending the SMS, SMSC will send the delivery report that the message has been delivered.</p>
<p>I hope you find this tutorial useful. Feel free to reach <a target="_blank" href="https://101node.io">out</a> if you have any <strong>questions.</strong></p>
<h4 id="heading-further-reading"><strong>Further reading:</strong></h4>
<p>If you would like to learn more about SMPP, check out: <a target="_blank" href="http://opensmpp.org/specifications.html">http://opensmpp.org/specifications.html</a></p>
<p><em>Don’t hesitate to clap if you considered this a worthwhile read!</em></p>
<p>Follow <a target="_blank" href="https://www.freecodecamp.org/news/author/thatshailesh/">Shailesh Shekhawat</a> to get notified whenever I publish a new post.</p>
<p><em>Originally published at <a target="_blank" href="https://101node.io/blog/send-sms-in-node-js-via-smpp-gateway/">101node.io</a> on September 16, 2018.</em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
