Custom Search

Tuesday, January 7, 2014

Python How to Send SMS using SMPP Protocol

Python How to Send SMS via Short Message Peer-to-Peer using
smpplib

import smpplib
import settings

client = None
try:
        client = smpplib.client.Client(settings.SMS_SYSTEM_HOSTNAME, settings.SMS_SYSTEM_PORT)
        client.connect()
        try:
                client.bind_transmitter(system_id=settings.SMS_SYSTEM_ID, password=settings.SMS_SYSTEM_PASSWORD)

                client.send_message(source_addr_ton=smpplib.consts.SMPP_TON_INTL,
                        source_addr='9535134654',
                        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
                        destination_addr='9535134654',
                        short_message='test Message`')
        finally:
                #print "==client.state====", client.state
                if client.state in [smpplib.consts.SMPP_CLIENT_STATE_BOUND_TX]:
                        #if bound to transmitter
                        try:
                                client.unbind()
                        except smpplib.exceptions.UnknownCommandError as ex:
                                #https://github.com/podshumok/python-smpplib/issues/2
                                try:
                                        client.unbind()
                                except smpplib.exceptions.PDUError as ex:
                                        pass
finally:
        if client:
                #print "==client.state====", client.state      
                client.disconnect()
                #print "==client.state====", client.state




Ref Sites
=======
https://github.com/podshumok/python-smpplib
http://messagetools.googlecode.com/svn/trunk/smppClient.py
http://messagetools.googlecode.com/svn/trunk/smpplib/test_client.py
www.nowsms.com/discus/messages/1/SMPP_v3_4_Issue1_2-24857.pdf



12 comments:

  1. there is an error of "No module named settings". Please tell me how to import this module.

    ReplyDelete
  2. dont use settings file.., just directly enter the host, port no, id and pass in the code

    ReplyDelete
  3. need to install any s/w

    ReplyDelete
  4. $ python smpp.py
    ==client.state==== 2
    ==client.state==== 2
    ==client.state==== 0

    How can i fix this??

    ReplyDelete
    Replies
    1. are you pass this problem ? i have too

      Delete
    2. #python smpp.py
      Traceback (most recent call last):
      File "smpp.py", line 25, in
      from smpplib import command, pdu
      ImportError: No module named smpplib

      bloger doing bulshit

      Delete
  5. no module named smpp. what do i do???

    ReplyDelete
    Replies
    1. https://pypi.org/project/python3-smpplib/#files

      Delete
    2. This comment has been removed by the author.

      Delete
  6. Hi, SMPP services are widely used to send a high volume of messages in a single click with best-in-class delivery. So, if you have huge SMS consumption that must get this services to get success in this competitive edge. SMPP Client Panel

    ReplyDelete
  7. how we can send sms to multiple numbers ?

    ReplyDelete