Varius Message Router Send SMS Integration Programming Code Examples

An application can communicate with Varius Message Router to send out SMS messages using the following methods:

Using SMTP
Your application points to Varius Message Router as its SMTP server for sending out emails. The email recipients are in the format of @fluidsms.com. The content of the email message will be the SMS message.

Code examples:
C#   C++   Java   Perl   PHP   Python   VB.Net 

Using HTTP
Your application accesses a custom URL in Varius Message Router to send out SMS messages using HTTP GET.

The format of the custom URL is

http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>

Code examples:
C#   C++   Java   Perl   PHP   Python   VB.Net 

VB.Net send SMS messages using SMTP

Imports System.Net.Mail

‘######
‘Set the IP address of Varius Message Router as the SMTP server to send out email.
‘The recipient email address format is <%recipient_mobile_number%>@fluidsms.com
‘We are assuming the following:
‘- IP address of Varius Message Router is 192.168.0.88
‘- The licensed user email address is sales@variustech.com
‘- The mobile number is 91111111
‘######

Dim mail As New MailMessage
mail.To.Add(“91111111@fluidsms.com”)
mail.From = New mailAddress(“sales@variustech.com”)
mail.Subject = “Test email subject”
mail.Body = “Test SMS message from Varius Message Router”

Dim smtp As New SmtpClient(“192.168.0.88”)
smtp.Port = “25”
smtp.Send(mail)

VB.Net send SMS messages using HTTP

Imports System
Imports System.Net
Imports System.IO

‘######
‘URL format is:
‘http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
‘We are assuming the following:
‘- IP address of Varius Message Router is 192.168.0.88
‘- The user name /password is testuser / testpassword
‘- The mobile number is 91111111
‘######

Dim url as String = “http://192.168.0.88/pages/sendmsg.aspx”
Dim wclient as WebClient = New WebClient()
wclient.QueryString.Add(“user”, “testuser”)
wclient.QueryString.Add(“password”, “testpassword”)
wclient.QueryString.Add(“to”, HttpUtility.UrlEncode(“91111111”))
wclient.QueryString.Add(“text”, HttpUtility.UrlEncode(“Test SMS message from Varius Message Router”))
wclient.Headers.Add(“user-agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)”)

Dim rstream As Stream = wclient.OpenRead(url)
Dim sreader As StreamReader = new StreamReader(rstream)
Dim result As String = sreader.ReadToEnd()
rstream.Close()
sreader.Close()
return result

C# send SMS messages using SMTP

using System.Net.Mail;

/*
######
Set the IP address of Varius Message Router as the SMTP server to send out email.
The recipient email address format is <%recipient_mobile_number%>@fluidsms.com
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The licensed user email address is sales@variustech.com
– The mobile number is 91111111
######
*/

MailMessage mail = new MailMessage();
mail.To.Add(“91111111@fluidsms.com”);
mail.From = new MailAddress(“sales@variustech.com”);
mail.Subject = “Test email subject”;
mail.Body = “Test SMS message from Varius Message Router”;

SmtpClient smtp = new SmtpClient(“192.168.0.88”);
smtp.Port = 25;
smtp.Send(mail);

C# send SMS messages using HTTP

using System;
using System.Net;
using System.IO;

/*
######
URL format is:
http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The user name /password is testuser / testpassword
– The mobile number is 91111111
######
*/

string url =”http://192.168.0.88/pages/sendmsg.aspx”;
WebClient wclient = new WebClient();
wclient.QueryString.Add(“user”, “testuser”);
wclient.QueryString.Add(“password”, “testpassword”);
wclient.QueryString.Add(“to”, “91111111”);
wclient.QueryString.Add(“text”, HttpUtility.UrlEncode(“Test SMS message from Varius Message Router”));
client.Headers.Add(“user-agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)”);

Stream rstream = wclient.OpenRead(url);
StreamReader sreader = new StreamReader(rstream);
string result = sreader.ReadToEnd();
rstream.Close();
sreader.Close();
return result;

PHP send SMS messages using SMTP

/*
######
Set the IP address of Varius Message Router as the SMTP server to send out email.
The recipient email address format is <%recipient_mobile_number%>@fluidsms.com
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The licensed user email address is sales@variustech.com
– The mobile number is 91111111
######
*/

require ‘PHPMailerAutoload.php’;

$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ‘192.168.0.88’;
$mail->From = ‘sales@variustech.com’;
$mail->addAddress(‘91111111@fluidsms.com’);
$mail->Subject = ‘Test email subject’;
$mail->Body = ‘Test SMS message from Varius Message Router’;

if(!$mail->send()) {
echo ‘Message could not be sent.’;
echo ‘Mailer Error: ‘ . $mail->ErrorInfo;
} else {
echo ‘Message has been sent’;
}

PHP send SMS messages using HTTP

/*
######
URL format is:
http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The user name /password is testuser / testpassword
– The mobile number is 91111111
######
*/

$url = ‘http://192.168.0.88/pages/sendmsg.aspx?’;
$qarr = array(
‘user’ => ‘testuser’,
‘password’ => ‘testpassword’,
‘to’ => ‘91111111’,
‘text’ => “Test SMS message from Varius Message Router”,
);
$qstr = http_build_query($qarr);
$rstream = fopen($url.$qstr,’r’);
$result = fread($rstream,1024);
fclose($rstream);
if (strpos($result, ‘SUCCESS’) !== false){
echo “Send SMS message success”;
} else {
echo “Send SMS message failure”;
}

Java send SMS messages using SMTP

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

/*
######
Set the IP address of Varius Message Router as the SMTP server to send out email.
The recipient email address format is <%recipient_mobile_number%>@fluidsms.com
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The licensed user email address is sales@variustech.com
– The mobile number is 91111111
######
*/

public class SendEmail
{
public static void main(String [] args){
String to = “91111111@fluidsms.com”;
String from = “sales@variustech.com”;
String host = “192.168.0.88”;

//Get the session object
Properties properties = System.getProperties();
properties.setProperty(“mail.smtp.host”, host);
Session session = Session.getDefaultInstance(properties);

//compose the message
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject(“Test email subject”);
message.setText(“Test SMS message from Varius Message Router”);

// Send message
Transport.send(message);
System.out.println(“Email message sent successfully”);

}catch (MessagingException mex) {mex.printStackTrace();}
}
}

Java send SMS messages using HTTP

import java.io.*;
import java.net.*;

/*
######
URL format is:
http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The user name /password is testuser / testpassword
– The mobile number is 91111111
######
*/

HttpURLConnection conn;
BufferedReader sreader;
String line = “”;
String result = “”;
String aurl =”http://192.168.0.88/pages/sendmsg.aspx?”;
String charset = “UTF-8”;
String querystr = String.format(“user=%s&password=%s&to=%s&text=%s”,
URLEncoder.encode(“testuser”, charset),
URLEncoder.encode(“testpassword”, charset),
URLEncoder.encode(“91111111”, charset),
URLEncoder.encode(“Test SMS message from Varius Message Router”, charset)
);

URL finalurl = new URL(aurl + querystr);
conn = (HttpURLConnection) finalurl.openConnection();
conn.setRequestMethod(“GET”);
conn.connect();
sreader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = sreader.readLine()) != null) {
result += line;
}
sreader.close();
conn.disconnect();
System.out.println(result);
return result;

Python send SMS messages using SMTP

import smtplib

”’
######
Set the IP address of Varius Message Router as the SMTP server to send out email.
The recipient email address format is <%recipient_mobile_number%>@fluidsms.com
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The licensed user email address is sales@variustech.com
– The mobile number is 91111111
######
”’

FROM = ‘sales@variustech.com’
TO = [“91111111@fluidsms.com”]
SUBJECT = “Test email subject”
TEXT = “Test SMS message from Varius Message Router”

message = “””\
From: %s
To: %s
Subject: %s

%s
“”” % (FROM, “, “.join(TO), SUBJECT, TEXT)

server = smtplib.SMTP(‘192.168.0.88’)
server.sendmail(FROM, TO, message)
server.quit()

Python send SMS messages using HTTP

import urllib
import urllib2

”’
######
URL format is:
http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The user name /password is testuser / testpassword
– The mobile number is 91111111
######
”’

aurl = ‘http://192.168.0.88/pages/sendmsg.aspx?’
querystr = { ‘user’:’testuser’, ‘password’:’testpassword’, ‘to’:’91111111′, ‘text’:’Test SMS message from Varius Message Router’ }
encodedstr = urllib.urlencode(querystr)
url = aurl + encodedstr
result = urllib2.urlopen(url).read()

Perl send SMS messages using SMTP

use strict;
use warnings;

=for comment
######
Set the IP address of Varius Message Router as the SMTP server to send out email.
The recipient email address format is <%recipient_mobile_number%>@fluidsms.com
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The licensed user email address is sales@variustech.com
– The mobile number is 91111111
######
=cut

use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP ();
use Email::Simple ();
use Email::Simple::Creator ();

my $smtpserver = ‘192.168.0.88’;
my $smtpport = 25;

my $transport = Email::Sender::Transport::SMTP->new({
host => $smtpserver,
port => $smtpport,
});

my $email = Email::Simple->create(
header => [
To => ‘91111111@fluidsms.com’,
From => ‘sales@variustech.com’,
Subject => ‘Test email subject’,
],
body => “Test SMS message from Varius Message Router\n”,
);

sendmail($email, { transport => $transport });

Perl send SMS messages using HTTP

use strict;
use warnings;
use LWP::Simple;
use URI;

=for comment
######
URL format is:
http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The user name /password is testuser / testpassword
– The mobile number is 91111111
######
=cut

my $uri_object = URI->new(‘http://192.168.0.88/pages/sendmsg.aspx’);
$uri_object->query_form(‘user’ => ‘testuser’, ‘password’ => ‘testpassword’, ‘to’ => ‘91111111’, ‘text’ => ‘Test SMS message from Varius Message Router’);

$contents = get($uri_object);

C++ send SMS messages using HTTP

#include <stdio.h>
#include <iostream>
#include <curl/curl.h>
using namespace std;

/*
######
Note: We are using the curl and libcurl library
URL format is:
http://<%ip_address%>/pages/sendmsg.aspx?user=<%username%>&password=<%password%>&to=<%recipient_mobile_no%>&text=<%sms_text%>
We are assuming the following:
– IP address of Varius Message Router is 192.168.0.88
– The user name /password is testuser / testpassword
– The mobile number is 91111111
######
*/

int main(void) {
CURL *curl;
CURLcode res;

curl = curl_easy_init();
if(curl) {
string aurl = “http://192.168.0.88/pages/sendmsg.aspx?”;
char *username = curl_easy_escape(curl, “testuser”, 0);
char *password = curl_easy_escape(curl, “testpassword”, 0);
char *smsto = curl_easy_escape(curl, “91111111”, 0);
char *smstext = curl_easy_escape(curl, “Test SMS message from Varius Message Router”, 0);

string url = aurl;
url += “&user=” + username;
url += “&password=” + password;
url += “&to=” + smsto;
url += “&text=” + smstext;

char * urlchar = new char[url.size() + 1];
copy(url.begin(), url.end(), urlchar);
urlchar[url.size()] = ‘\0’;

curl_easy_setopt(curl, CURLOPT_URL, urlchar);

res = curl_easy_perform(curl);

//check for errors
if(res != CURLE_OK)
fprintf(stderr, “Send SMS message failure: %s\n”, curl_easy_strerror(res));

curl_easy_cleanup(curl);

}
return 0;
}