FaxMan Jr
Batch Sending of Faxes

Many sending applications are automated and have minimal user interaction.  The user interface may be limited to a configuration utility or may be absent entirely.  The faxes may come out of a database table or other source. There may be more faxes that need to be sent at a given time then there are com ports.  This is the kind of scenario that the FaxMan SDK excels at.  Most developers who are writing Client Server Applications or broadcast fax applications will choose the FaxMan SDK because it includes scheduling logic, automatic retries, and dynamically handles a pool of modems with no need to add or modify code on the application developers part.

Having explained the virtues of the FaxMan SDK I will go on to say that FaxMan Jr can also be used for writing a fax broadcast application it just takes more work on the part of the application developer.  I will not attempt to recreate all of FaxMan SDK's features in the code sample below. This is not to say that writing modem pooling and scheduling logic aren't important- just that they are outside the scope of this example.  Instead I will focus only on how to send multiple faxes on one modem. 

The key to keeping one port busy is to watch for the CompletionStatus.  This event gets fired each time a fax operation is done, whether successful or not.  This is the event to schedule the next fax in. For this sample I will use a simple queue for holding multiple Fax objects. In your application you might be polling your database on a timer, in the CompletionStatus, or it may be run on demand by the System or DB Scheduler. The fax information from your database can then be supplied to the Fax object from one or more tables.

// Form Level Variables
DataTech.FaxManJr.Faxing _faxing;
System.Collections.Queue _faxJobs;

// Somewhere in your startup code choose your modem
_faxing.Modem = new Modem(3, FaxClass.Class1);

private void mnuQueueUp100Faxes_Click(object sender, System.EventArgs e)
   for (int i = 0; i < 100; i++)
   {          DataTech.FaxManJr.Fax fax = new DataTech.FaxManJr.Fax();

       // Use report generating tool to generate pdf file bypassing printer driver
       string myPdfReport = "c:\\myPdfReport.pdf";

       // Generate Fax File from pdf file using Pdf AddOn
       // Give the fmf file a unique name unless your report names are already unique
       string importedfile = String.Format("{0}{1}{2}.fmf",
           myPdfReport.Length - myPdfReport.LastIndexOf("\\")), i);
       if (! (System.IO.File.Exists(importedfile)) )
           _faxing.ImportFiles(myPdfReport, importedfile);

       // Get fax information from database
       fax.FaxNumber = @"123-4567";
       fax.UserData = String.Format("Fax {0}", i);
     DataTech.FaxManJr.Fax qFax = (DataTech.FaxManJr.Fax)_faxJobs.Dequeue();

// This is the event where the modem is ready to send the next fax in the Queue
private void _faxing_FaxCompletionStatus(object sender, FaxEventArgs args)
   // reschedule if failed the first time
   // by sending to end of queue
   if ( (FaxError.Ok != args.Fax.FaxError) && (args.Fax.UserData.Length < 10) )
       args.Fax.UserData = String.Format("Failed To Send Fax {0}, Trying Again", args.Fax.UserData);

   // Send the next fax in the queue
   if (_faxJobs.Count > 0)
       DataTech.FaxManJr.Fax qFax = (DataTech.FaxManJr.Fax)_faxJobs.Dequeue();

// And finally while testing you probably want // to be able to cancel this operation.
private void mnuStopBatchSend_Click(object sender, System.EventArgs e)

The main sample also demonstrates batch sending of faxes under the test menu. The main sample as well as this sample send the same fax to the same number so are limited in scope.  But with supplying the key information from your database like phone number and the file you want sent as well as any banner or cover page information you should at least have a good start.  And finally if you want advanced scheduling options including modem pools consider the FaxMan SDK.



© 2014 Data Techniques, Inc. All Rights Reserved.

Send comments on this topic.