Perl Fax – Sending One or More Files to Multiple Recipients with SendfaxEx_2

25 Nov 2016 This code sample is deprecated and in process of being removed. Check out our new code libraries and usage documentation on InterFAX @ Github.
Download the Perl fax code samples.

In this section, the provided Perl fax script sends one or more faxes to one or more recipients with SendfaxEx_2.

The Perl fax snippet below reads a number of files, submits the fax to the Web service (with multiple attachments), and indicates whether the submission succeeded. The return value of a successful submission is the transaction ID (positive number) of the fax in the system. Other return values indicate a failure (for more details, see Web Service Return Codes).

Sending a fax from Perl to one or more recipients with one or more attached files is done using the SendfaxEx_2 method, which has more flexible sending capabilities than Sendfax (for more details, see Side-by-side Comparison of Web Service Methods).


#/**************** Settings begin **************/
my $username  = ''; # Enter your Interfax username here
my $password  = ''; # Enter your Interfax password here
# Semicolon-delimited list of destination fax numbers
my $faxNumbers = '+12077301111;+492077301222;+442077301333';
# Optional semicolon-delimited list of recipient names; one per fax number
my $contacts = 'Rachel Burns;Albie Eins;Max Planck';
# Files to fax. Files are assumed to be in the local directory
my @files  = ('sample.txt', 'sample.html');
my $postponeTime      = '2001-12-31T00:00:00-00:00';
my $retries           = '3';
my $csid              = 'AA CSID';
my $pageHeader        = 'To: {To} From: {From} Pages: {TotalPages}';
my $subject           = 'Anything goes';
my $replyEmail        = '';
my $pageSize          = 'A4';
my $pageOrientation   = 'Portrait';
my $highResolution    = 0;
my $fineRendering     = 1;
my $NS = 'http://www.interfax.cc';
#/**************** Settings end ****************/


my $fileTypes  = '';
my $fileData   = '';
my $fileSizes  = '';
my ($file, $datafile);

for(my $i = 0; $i uri($NS)
    ->on_action( sub { join '/', $NS, $_[1] } ) 
    ->proxy('https://ws.interfax.net/dfs.asmx?wsdl');

my $result = $client
    ->call(SOAP::Data->name('SendfaxEx_2')->attr({xmlns => $NS}) =>
            SOAP::Data->name('Username')->value($username)->type(''),
            SOAP::Data->name('Password')->value($password)->type(''),
            SOAP::Data->name('FaxNumbers')->value($faxNumbers)->type(''),
            SOAP::Data->name('Contacts')->value($contacts)->type(''),
            SOAP::Data->name('FilesData')->value($fileData)->type(''),
            SOAP::Data->name('FileTypes')->value($fileTypes)->type(''),
            SOAP::Data->name('FileSizes')->value($fileSizes)->type(''),
            SOAP::Data->name('Postpone')->value($postponeTime)->type(''),
            SOAP::Data->name('RetriesToPerform')->value($retries)->type(''),
            SOAP::Data->name('CSID')->value($csid)->type(''),
            SOAP::Data->name('PageHeader')->value($pageHeader)->type(''),
            SOAP::Data->name('JobID')->value('')->type(''),
            SOAP::Data->name('Subject')->value($subject)->type(''),
            SOAP::Data->name('ReplyAddress')->value($replyEmail)->type(''),
            SOAP::Data->name('PageSize')->value($pageSize)->type(''),
            SOAP::Data->name('PageOrientation')->value($pageOrientation)->type(''),
            SOAP::Data->name('IsHighResolution')->value($highResolution)->type(''),
            SOAP::Data->name('IsFineRendering')->value($fineRendering)->type('')
    );


if ( $result->fault ) {
    print $result->faultstring . "\n";
} else {
    if( $result->valueof('//SendfaxEx_2Result') > 0 ) {
        print "Success. TransactionID=" . $result->valueof('//SendfaxEx_2Result') . "\n";
    } else {
        print "Error, return code=" . $result->valueof('//SendfaxEx_2Result') . "\n";
    }
}