Send multiple messages

To send a Message to multiple mobile phone numbers with one method call you need to call the SendMessageMultipleRecipients method of the send service 2 object. An example page of how to do this is included in the zip file that you downloaded, the script for it is as follows


function processForm()

' Turn off error handling as we will handle any errors ourselves
on error resume next

' Create the service object
dim sendService
set sendService = Server.CreateObject("Esendex.SendService.2")

' Was there a problem setting up the object?
if err.number <> 0 then
  processForm = "Unable to create Esendex.SendService.2 object. Ensure COM object is registered. Error description: " + err.Description
  exit function
end if

' Setup the send service object
sendService.Initialise Request.Form("Username"), Request.Form("Password"), Request.Form("Account")

' Attempt to send the messages
dim messageIDs
set messageIDs = sendService.SendMessageMultipleRecipients(Request.Form("recipients"), Request.Form("body"), 1)
' Handle any errors
if err.number <> 0 then
  processForm = "Unable to send message: " + err.Description
  exit function
else
  processForm = "The messages were delivered. The message id's were: "
  Dim index
  for index = 1 To messageIDs.Count
    processForm = processForm + messageIDs(index) + ", "
  next
end if
end function

If you break this down you will see that it's very similar to sending a text Message but with a different method call on the Send Service object. You start by creating a Send Service object.


dim sendService
set sendService = Server.CreateObject("Esendex.SendService.2") 

Next you have to initialise the Send Service object with your Account details.


sendService.Initialise Request.Form("Username"), Request.Form("Password"), Request.Form("Account")

The Account details are the user name and password that you sign into the website with and your Account Reference, usually starting EX00 followed by five numbers, i.e. EX0012345.

Now that the Send Service knows which Account to use you can send your Message.


dim messageIDs		
set messageIDs = sendService.SendMessageMultipleRecipients(Request.Form("recipients"), Request.Form("body"), 1)

The main differences between this method and SendMessage are the recipients and the return value. The recipients parameter is a comma delimited string of the mobile numbers you want to send your Message to i.e. "447712345678, 447798765432". The return value is now an array of Message Ids instead of a single Message Id.

The array is ordered in the same order as your recipients. The other parameters in the method call are the same as SendMessage. Body is the message you want to send and Type is the type of the Message. In this case the type is set to 1, which is text but you can also set the type to Binary (2), SmartMessage (3) or Unicode (4). One thing to note is that duplicate numbers are removed from the recipients string before the Messages are sent, for example.

If you had a recipients list of "447700900123, 447700900123, 447700900456", only two Messages would be sent, one to 447700900123 and one to 447700900456. You would also only get back two Message Ids.