C# Fax – Send Faxes to Multiple Recipients Using SendfaxEx_2

Download the C# fax API zip file.

This sample explains how to send one or more C# faxes to one or more recipients using the method SendfaxEx_2, which provides more flexible sending capabilities than Sendfax (for more details, see Side-by-side Comparison of Web Service Methods).

The C# fax API snippet below reads a few submitted files, submits a fax with multiple attachments to the Web service, and indicates if the submission succeeded or failed.

If the return value is the transaction ID (positive number) of the fax in the system, this means the submission was successful. Failure is indicated by any other return values (for more details, see Web Service Return Codes).


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SendfaxEx_2
{
    class Program
    {
        static void Main(string[] args)
        {
            string username = "";
            string password = "";
            string faxNumbers = "00442071499926"; // to send to multiple numbers, separate by [;] without the brackets
            string contacts = ""; // to send to multiple contacts, separate by [;] without the brackets
            // read each file into a separate byte array
            byte[] file1data = System.IO.File.ReadAllBytes("C:\\Docs\\Interfax\\iftestwslex.docx"); // can use as many files as system limitation, this example has 2
            byte[] file2data = System.IO.File.ReadAllBytes("C:\\Docs\\Interfax\\iftestwslex.pdf"); // can use as many files as system limitation, this example has 2
            // get extensions of each file
            string fileTypes = System.IO.Path.GetExtension("C:\\Docs\\Interfax\\iftestwslex.docx").TrimStart('.') + ";" + System.IO.Path.GetExtension("C:\\Docs\\Interfax\\iftestwslex.pdf").TrimStart('.');
            // get size of each file
            string fileSizes = file1data.Length.ToString() + ";" + file2data.Length.ToString();
            // combine into a single byte array
            byte[] combinedFileData = new byte[file1data.Length + file2data.Length];
            System.Buffer.BlockCopy(file1data, 0, combinedFileData, 0, file1data.Length);
            System.Buffer.BlockCopy(file2data, 0, combinedFileData, file1data.Length, file2data.Length);
            // set postpone time. for no postpone time, use a date in the past
            DateTime postponeTime = DateTime.Now.AddHours(0);
            int retriesToPerform = 3;
            string csid = "InterFAX";
            // for page header formatting, see options
            string pageHeader = "To: {To} From: {From} Pages: {TotalPages}";
            string subject = "Test WS Fax";
            string replyAddress = "";
            string pageSize = "A4";
            string pageorientation = "Portrait";
            // use high resolution for maintaining original document scale (increases transmission duration)
            bool isHighResolution = false;
            // use fine rendering for graphical elements
            bool isFineRendering = false;
            // end of parameters
            interfax.InterFax interfaxWebServiceOutbound = new interfax.InterFax();
            long resultStatus = interfaxWebServiceOutbound.SendfaxEx_2(username, password, faxNumbers, contacts, combinedFileData, fileTypes, fileSizes, postponeTime, retriesToPerform, csid,
            pageHeader, "", subject, replyAddress, pageSize, pageorientation, isHighResolution, isFineRendering);
            if (resultStatus > 0) // if the result is positive, it's the TransactionID created
            {
                Console.WriteLine(string.Format("Created Fax with TransactionID {0}.", resultStatus));
            }
            else // if the result is negative, it's an error code
            {
                Console.WriteLine(string.Format("Failed with Error Code {0}.", resultStatus));
            }
            Console.ReadLine(); // use this to keep console open (waiting for keypress) after it is finished
        }
    }
}