ColdFusion Fax – Send Multiple Files to Multiple Recipients with SendfaxEx_2

This section provides a ColdFusion fax snippet, which reads a number of files, concatenates them into one string, 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 ColdFusion 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).


<!--- Username and password for the Interfax account. --->
<cfset interfaxUsername = "">
<cfset interfaxPassword = "">
<cfset faxNumbers = "+49(711)4900-8548">

    Read the files into memory and concatenate them into a single string.
<cffile action="readbinary" file="#ExpandPath('.')#/sample.pdf" variable="fileSamplePDF">
<cffile action="readbinary" file="#ExpandPath('.')#/sample.doc" variable="fileSampleDOC">
<cffile action="readbinary" file="#ExpandPath('.')#/sample.txt" variable="fileSampleTXT">
    //  Concatenate the files
    filesBuffer = createObject("java", "").init();
    filesBuffer.write(fileSamplePDF, 0, Len(fileSamplePDF));
    filesBuffer.write(fileSampleDOC, 0, Len(fileSampleDOC));
    filesBuffer.write(fileSampleTXT, 0, Len(fileSampleTXT));

    filesData = filesBuffer.toByteArray();

    //  Build a list of file types (elements separated by ;)
    filesTypes    = "PDF;DOC;TXT";

    //  Build a list with the size of each file from the concatenated buffer
    filesSizes    = Len(fileSamplePDF) & ";" & Len(fileSampleDOC) & ";" & Len( fileSampleTXT );

    userHighResolution = true;
    useFineRendering   = true;

<!--- Create and call the web service --->
<cfset faxWebService = CreateObject("webservice", "")>

    faxID = faxWebService.SendFaxEx_2(interfaxUsername, interfaxPassword, faxNumbers, "", filesData, filesTypes, filesSizes,
                        CreateDateTime(2004, 5, 5, 10, 10, 10),  /* Date to send the fax. If it's in the past then the fax is sent ASAP */
                        0,                                       /* Number of retries to perform */
                        "",                                      /* CSID */
                        "",                                      /* PageHeader*/
                        "",                                      /* JobID */
                        "Fax subject", "", "A4", "Portrait",

<!--- Check to see if the fax was sent ok. --->
<cfif faxID gt 0>
    Fax submitted ok. Transaction ID: #faxID#
    Error submitting fax.
    Return code: #faxID#.<br>
    Error message:  #faxID#