Fax VB.NET – Send One or More Files to Multiple Recipients with SendfaxEx_2

Download the fax VB.NET project files.

This section shows how to send faxes with VB.NET to one or more recipients using SendfaxEx_2.

The fax VB.NET snippet below does the following: reads a number of files, submits the fax to the Web service (with multiple attachments), and indicates the success/failure of the submission.

For a successful submission, the return value is the transaction ID (positive number) of the fax in the system. A failure is indicated by any other return values (for more details, see Web Service Return Codes).

Sending a fax with VB.NET to one or more recipients with one or more attached files is done using the SendfaxEx_2 method, which provides more flexible sending capabilities than Sendfax (for more details, see Side-by-side Comparison of Web Service Methods).


Sub Main()
        Dim username As String = "my username"
        Dim password As String = "my password"
        Dim faxNumbers As String = "+442079876543;+12125555555"
        Dim contacts As String = "Name 1;Name 2"
        Dim path1 As String = "c:\temp\1.pdf"
        Dim path2 As String = "c:\temp\1.docx"
        ' read files data
        Dim file1data() As Byte = IO.File.ReadAllBytes(path1)   '1st document
        Dim file2data() As Byte = IO.File.ReadAllBytes(path2)   '2nd document
        ' combine into a single byte array
        Dim data(file1data.Length + file2data.Length - 1) As Byte
        Array.Copy(file1data, data, file1data.Length)
        Array.Copy(file2data, 0, data, file1data.Length, file2data.Length)
        Dim fileTypes As String = IO.Path.GetExtension(path1).TrimStart("."c) & ";" & IO.Path.GetExtension(path2).TrimStart("."c)
        Dim fileSizes As String = file1data.Length.ToString & ";" & file2data.Length.ToString

        Dim postponeTime As DateTime = DateTime.Now.AddHours(2) ' in two hours. use any PAST time to send ASAP
        Dim retriesToPerform As Integer = 2
        Dim csid As String = "My CSID"
        Dim pageHeader As String = "To: {To} From: {From} Pages: {TotalPages}"
        Dim subject As String = "My Subject"
        Dim replyAddress As String = "myemail@mydomain.com"
        Dim pageSize As String = "A4"
        Dim pageorientation As String = "Portrait"
        Dim isHighResolution As Boolean = False 'this will speed up your transmission
        Dim isFineRendering As Boolean = False  'fine will fit more graphics, while normal (false) will fit more textual documents

        Dim ifws As New interfax.InterFax()
        Dim st As Long = ifws.SendfaxEx_2( _
        username, _
        password, _
        faxNumbers, _
        contacts, _
        data, _
        fileTypes, _
        fileSizes, _
        postponeTime, _
        retriesToPerform, _
        csid, _
        pageHeader, _
        "", _
        subject, _
        replyAddress, _
        pageSize, _
        pageorientation, _
        isHighResolution, _
        isFineRendering)

        Console.WriteLine("Status is " & st)

    End Sub