Run a campaign from the command line
You can find out how to configure and run campaigns from the SMS Server manager here.
This document explains how to run an existing campaign from the command line.
1. Create a script to run the Campaign
First we’ll create a small script that will run the campaign. In this example we use VBScript.
Copy and paste the following script into notepad and save it as ”C:\AuronScripts\SendCampaign1.vbs”.
Create the ‘AuronScripts’ directory if it does not exist.
Set objCampaignManager = CreateObject("AxMmServer.CampaignManager") nBatchID = objCampaignManager.Run("CAMPAIGN1", "Automated run") If objCampaignManager.LastError <> 0 Then WScript.Echo objCampaignManager.LastErrorDescription WScript.Quit 1 End If WScript.Echo "Campaign completed; BatchID: " & nBatchID
The text ‘CAMPAIGN1‘ needs to be changed to the name of your campaign.
2. Run the script
To run the campaign we just need to run the script.
There are two ways to run the script:
- Run it by double-clicking in the explorer
- Run it from the command line using ‘cscript’
The difference is that when running from the explorer all ‘WScript.Echo’ lines will cause a pop-up to display while running from the command line will just print those lines to the console.
Most of the time running from the command line without pop-ups is more convenient.
To run the script from the command line first open up a command line by typing ‘Windows-R‘ and ‘cmd<enter>‘.
The script will run and display the BatchID when it ends.
3. (Optional) Improvements
You can customize the message text used in the campaign. This can be useful if you want to use the same set of phone-numbers or e-mail addresses to send different messages to but you don’t want to configure all of these as different campaigns.
To customize the message we will have to make the following change to the script:
Set objCampaignManager = CreateObject("AxMmServer.CampaignManager") objCampaignManager.CustomSmsMessage = "Hello %FirstName%, this message was customized at the last moment" 'objCampaignManager.CustomSubject = "Regarding %Subject%" 'objCampaignManager.CustomPlainTextMessage = "Hello %FirstName%, this message was customized at the last moment" 'objCampaignManager.CustomHtmlMessage = "Hello <strong>%FirstName%</strong>, this message was customized at the last moment" nBatchID = objCampaignManager.Run("CAMPAIGN1", "Automated run") If objCampaignManager.LastError <> 0 Then WScript.Echo objCampaignManager.LastErrorDescription WScript.Quit 1 End If WScript.Echo "Campaign completed; BatchID: " & nBatchID
Also, we now have to learn one thing about VBScript to make the best use of this: The lines starting with a single quote: “‘” are commented out. And will be ignored when running the script. To make those lines take effect you will need to remove the single quote.
Depending on whether you are sending an SMS or an e-mail you can enable / disable the appropriate ‘objCampaignManager.Custom..’ lines. In the custom message you can use the same placeholders to refer to the fields in the data source.