H-Sphere XML API - Create Mailboxes

This is the first of a few simple perl script that I wrote to help with some admin tasks, it uses the H-Sphere XML API to create mailboxes for existing accounts, the other scripts will be posted shortly.

#!/usr/bin/perl

use DBI(); 
#use strict;
use SOAP::Lite;
use Data::Dumper;

$serviceuri = 'cp.your-server.com';
use Env;

addEmail ('Account#', 'AccountUserName', 'AccountPassword', 'MAILBOX', 'MAILBOXPASSWORD', 'domain.com');


sub addEmail {

        my $account = $_[0];
        my $login = $_[1];
        my $password = $_[2];
        my $email = $_[3];
        my $pass = $_[4];
        my $domain = $_[5];


        # generate authtoken
        my $authtoken = SOAP::Data->name('at' => 
                \SOAP::Data->value(
                        SOAP::Data->type('int')->name('accountId' => $account),
                        SOAP::Data->type('string')->name('login' => $login),
                        SOAP::Data->type('string')->name('password' => $password)
                        )
                );

        my $request = new SOAP::Lite;
        $request->proxy("http://$serviceuri:8180/psoft/servlet/MailServices.jws");
        $request->uri('MailServices');

        my $result = $request->addMailbox ($authtoken,  SOAP::Data->type('string' => $email),
                                                        SOAP::Data->type('string' => $domain),
                                                        SOAP::Data->type('string' => $pass),
                                                        SOAP::Data->type('string' => ""));
        if ($result->fault) {
                printf "2 - ($account) there was an error, %s %s\n", $result->faultcode, $result->faultstring;
        }

print "\n";
}

Post a comment