Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Created November 18, 2015 10:53
Show Gist options
  • Save tomysmile/7269b6dc508f2dd5742a to your computer and use it in GitHub Desktop.
Save tomysmile/7269b6dc508f2dd5742a to your computer and use it in GitHub Desktop.
Gammu: Insert SMS

Injecting a message using SQL

   To send a message, you can either use gammu-smsd-inject, which does all
   the magic for you, or you can insert the message manually. The simplest
   example is short text message:
          INSERT INTO outbox (
              DestinationNumber,
              TextDecoded,
              CreatorID,
              Coding
          ) VALUES (
              '800123465',
              'This is a SQL test message',
              'Program',
              'Default_No_Compression'
          );
   Please  note usage of TextDecoded field, for Text field, you would have
   to hex encode the unicode text:
          INSERT INTO outbox (
              DestinationNumber,
              Text,
              CreatorID,
              Coding
          ) VALUES (
              '800123465',
              '005400680069007300200069007300200061002000530051004c002000740065007300740020006d006500730073006100670065',
              'Program',
              'Default_No_Compression'
          );

Injecting long message using SQL

   Inserting multipart  messages  is  a  bit  more  tricky,  you  need  to
   construct  also  UDH header and store it hexadecimally written into UDH
   field. Unless  you  have  a  good  reason  to  do  this  manually,  use
   gammu-smsd-inject.

   For long text message, the UDH starts with 050003 followed by byte as a
   message reference (you  can  put  anything  there,  but  it  should  be
   different  for  each message, D3 in following example), byte for number
   of messages (02 in example, it should be unique for  each  message  you
   send  to  same phone number) and byte for number of current message (01
   for first message, 02 for second, etc.).

   For example long text message of two parts could look like following:
          INSERT INTO outbox (
              CreatorID,
              MultiPart,
              DestinationNumber,
              UDH,
              TextDecoded,
              Coding
          ) VALUES (
              'Gammu 1.23.91',
              'true',
              '123465',
              '050003D30201',
              'Mqukqirip ya konej eqniu rejropocejor hugiygydewl tfej nrupxujob xuemymiyliralj. Te tvyjuh qaxumur ibewfoiws zuucoz tdygu gelum L ejqigqesykl kya jdytbez',
              'Default_No_Compression'
          )

          INSERT INTO outbox_multipart (
              SequencePosition,
              UDH,
              Class,
              TextDecoded,
              ID,
              Coding
          ) VALUES (
              2,
              '050003D30202',
              'u xewz qisubevumxyzk ufuylehyzc. Nse xobq dfolizygqysj t bvowsyhyhyemim ovutpapeaempye giuuwbib.',
              <ID_OF_INSERTED_RECORD_IN_OUBOX_TABLE>,
              'Default_No_Compression'
          )
   NOTE:
      Adding UDH means that you have less space for text, in above example
      you can use only 153 characters in single message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment