Java Fax - Retrieve new inbound faxes and download fax images

This is a more advanced Java code sample to show how to retrieve the list of inbound faxes, download the fax images and mark the processed faxes as "read". This code sample is based on the Java library for InterFAX available on Github.

This sample demonstrates how to retrieve the list of all "unread" (new) faxes in your inbound queue (by specifying unreadOnly: true), looping through the list of faxes and for each fax, downloading the fax image and marking this fax as "read".
By marking faxes as "read", they will not show up the next time that you search for all "unread" (new) faxes.

  
    // only get unread faxes
GetInboundFaxListOptions options =
  new GetInboundFaxListOptions();
options.setUnreadOnly(Optional.of(true));

// get the faxes
InboundFaxStructure[] faxes =
  interfax.getInboundFaxList(
    Optional.of(options)
);

for (InboundFaxStructure fax : faxes) {
  // save the fax image
  byte[] image = interfax.getInboundFaxImage(
      String.valueOf(fax.getMessageId())
  );
  FileOutputStream fos =
    new FileOutputStream(fax.getMessageId()+".pdf");
  fos.write(image);
  fos.close();

  // mark as read
  interfax.markInboundFax(
    String.valueOf(fax.getMessageId()),
    Optional.of(true)
  );
}

  

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