You are here:

ActiveXperts.com > Support > ActiveXperts SMS Messaging Server > Online > Create new Message directly

Activexperts Support Pages

Create a new SMS or e-mail Message directly without using the API

Introduction

With ActiveXperts SMS Messaging Server, you can create new messages using the SMS Messaging Server API. The API contains functions to filter, read, write, modify and delete messages in the Message Database.
The following VBScript sample shows how to create a new outgoing SMS message using the API:

   Set objMessageDB = CreateObject( "AxSmsServer.MessageDB" ) 
   Set objConstants = CreateObject( "AxSmsServer.Constants" ) 
   
   ' Open the Database
   objMessageDB.Open                        
   WScript.Echo "Open, result: " & objMessageDB.LastError
   
   ' Create new Message
   Set objMessage   = objMessageDB.Create   
   
   ' Set Properties
   objMessage.Direction    = objConstants.MESSAGEDIRECTION_OUT
   objMessage.Type         = objConstants.MESSAGETYPE_SMS
   objMessage.Status       = objConstants.MESSAGESTATUS_PENDING
   objMessage.Recipient    = "+31625044454"
   objMessage.Body         = "Hello, world!"
   
   ' Save the message
   objMessageDB.Save( objMessage )            
   
   ' Close the database
   objMessageDB.Close
The above script creates a new message in the Message Database. Using the API is not the only way to create a new message in the message Database.

However, there are several other ways to create a new message. This document describes the various ways to create a new message:

 

    Using the ADODB.Connection object

You can use the ADODB.Connection object to create a new message. This object works for the following SMS Messaging Server databases:
  • MS Access
  • MS SQL
  • MySQL
The following VBScript sample demonstrates how to create a new outgoing SMS message in an MS-Access Message Database:
   Const STR_DATABASE="C:\Program Files\ActiveXperts\SMS Messaging Server\Msg\Messages.mdb"
   
   Dim objConn, strSqlQuery
   
   Set objConn = CreateObject("ADODB.Connection")
   
   objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & STR_DATABASE & ";"
   
   strSqlQuery = "INSERT INTO Messages( Direction, Type, Status, Recipient, Body ) VALUES ( 2, 2, 1, '+31625044454', 'Hello, world' )"
   objConn.Execute( strSqlQuery )
   
   objConn.Close
   Set objConn = Nothing
Note that there are some hard-coded constants used in the code above: 2 to specify the direction (outgoing), 2 to specify the type (SMS), and 1 to specify the status (pending).
For an overview of all constants, click here.


The following script does the same thing, but instead of using an MS Access database, a SQL Server database is used:
   Const STR_CONNSTRING = "Driver={SQL Server};Server=dell05;Database=Messages;Uid=sa;Pwd=sa1"

   Dim objConn, strSqlQuery

   Set objConn = CreateObject("ADODB.Connection")

   objConn.Open STR_CONNSTRING

   strSqlQuery = "INSERT INTO Messages( Direction, Type, Status, Recipient, Body ) VALUES ( 2, 2, 1, '+31611223344', 'Hello, world' )"
   objConn.Execute( strSqlQuery )

   objConn.Close
   Set objConn = Nothing 

 

    Using MS SQL Server's "Query Analyzer"

When you use an MS SQL Server database with SMS messaging Server, you can simply enter the following line in SQL Server's "Query Analyzer" to create a new, outgoing SMS message:
   INSERT INTO Messages( Direction, Type, Status, Recipient, Body ) VALUES ( 2, 2, 1, '+31611223344', 'Hello, world' );
Note that there are some hard-coded constants used in the code above: 2 to specify the direction (outgoing), 2 to specify the type (SMS), and 1 to specify the status (pending).
For an overview of all constants, click here.


 

    Using MS SQL Server's "Stored Procedures"

You can use MS SQL "Stored Prcedures" to create a new message in the message Database. The following script shows how to create a new Stored Procedure to create a new SMS message in the Message Database (you can copy/paste the code in MS SQL's "Query Analyzer" and run it):
   CREATE PROCEDURE [dbo].[SendSMS]
    @Recipient  nvarchar(255)='', 
    @Message   nvarchar(255)=''
   AS
   INSERT INTO [dbo].[Messages] ( Direction, Type,  Status, Recipient, Body )
   VALUES ( 2, 2,  1, @Recipient, @Message );
Note that there are some hard-coded constants used in the code above: 2 to specify the direction (outgoing), 2 to specify the type (SMS), and 1 to specify the status (pending).
For an overview of all constants, click here.

Once the Stored Procedure is created, you can call the SendSMS function, for instance using MS SQL's "Query Analyzer":
   SendSMS '+31625044454", "Hello, world!"