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).


<cfoutput>

<!--- 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">
<cfscript>
    //  Concatenate the files
    filesBuffer = createObject("java", "java.io.ByteArrayOutputStream").init();
    filesBuffer.write(fileSamplePDF, 0, Len(fileSamplePDF));
    filesBuffer.write(fileSampleDOC, 0, Len(fileSampleDOC));
    filesBuffer.write(fileSampleTXT, 0, Len(fileSampleTXT));

    filesData = filesBuffer.toByteArray();
    filesBuffer.close();

    //  Build a list of file types (elements separated by ;) http://www.interfax.net/en/dev/webservice/reference.html#sendfaxex2
    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;
</cfscript>


<!--- Create and call the web service --->
<cfset faxWebService = CreateObject("webservice", "https://ws.interfax.net/dfs.asmx?WSDL")>

<cfscript>
    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", "mackmack@gmail.com", "A4", "Portrait",
                        userHighResolution,
                        useFineRendering
                        );
</cfscript>


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

Contact us today

Talk to a member of our team about the benefits InterFAX can bring to your organization's communications processes.

Contact us today