Java Fax – Send Plain-Text File with SendCharFax

In this Java fax code sample, you learn how to send a plain-text fax using the SendCharFax method. When sending a fax using SendCharFax, make sure your text is standard ASCII (no 8-bit characters), however note that it can include HTML markup (Using HTML causes automatic word wrapping, whereas regular text does not).

This code sample can be found in the ZIP file above (see the green ‘Download’ box), under the following path: interfaxJavaSamples > src > SendCharFaxFromJava.

The Java fax API snippet below shows you how to submit a plain-text file to the Web service, and receive indications of success/failure: 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). The SendCharFax sample is as follows:


import net.interfax.outbound.SendCharFax;
import net.interfax.outbound.SendCharFaxResponse;

public class FaxFromJava {

    /******** Begin settings ********/
    static String USERNAME = "";   // Enter your Interfax username here
    static String PASSWORD = "";   // Enter your Interfax password here
    static String FAX_NUMBER = ""; // Enter your designated fax number here in the format +[country code][area code][fax number], for example: +12125554874
    static String TEXT_TO_FAX = "My text goes here";
    static String FILE_TYPE = "TXT";
    /******** End settings ********/
    
    public static void main(String[] anArgs) {
        try {
            net.interfax.outbound.InterFaxSoapStub theBinding = (net.interfax.outbound.InterFaxSoapStub)new net.interfax.outbound.InterFaxLocator().getInterFaxSoap();
            theBinding.setTimeout(60000);
            System.out.println("Sending Fax using sendCharFax()");
            SendCharFax theParams = new SendCharFax(USERNAME,
                                                    PASSWORD,
                                                    FAX_NUMBER,
                                                    TEXT_TO_FAX,
                                                    FILE_TYPE);
            SendCharFaxResponse theResponse = theBinding.sendCharFax(theParams);

            long theReturnCode = theResponse.getSendCharFaxResult();
            System.out.println("sendCharFax() call returned with code: " + theReturnCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}