You are here:
ActiveXperts.com > Support > ActiveXperts SMS Messaging Server > Online > Create new Message directly
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:
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). 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
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).
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).SendSMS '+31625044454", "Hello, world!"