Using VBScript for Sending Faxes to Windows Fax Servers

Written by James McDonald

April 24, 2012

Note: I just discovered that this script doesn’t work with network faxes. What I mean by this is the fax device appears to the user but isn’t listed in the devices of the fax manager. So if you are wanting to send to a fax that is accessed via \\servername\faxname and the device isn’t directly connected to the remote server then this probably won’t work. Another thing I found is that this script works with FaxDevice (Seen by the System) but not VirtualFaxDevices (Seen per user).
I discovered this when I installed the Ricoh Lan-Fax M8 driver and then tried to use this script to print and it just wouldn’t do it.

After finding the example as listed here https://toggen.com.au/it-tips/vbs_send_fax

I have hacked a vbscript send fax file that sends from a Formtrap 7 Server

The good thing about this script is that your windows fax client will have a nicely filled in Recipient Name and Subject which aids in finding faxes in the future.

Call it using cscript and pass it a tiff file as the first argument along with the fax #, subject and recipient name.

Example:

rem spread over multiple lines for readability
C:\windows\System32\cscript.exe \
"D:\fthome\custom\bin\send_fax.vbs" \
"%1" "[fax_number]" "[subject]" "[recipient]"

Given these arguments:
File: D:\fthome\v7\DelTemp\fts9CB02.tif
Recipient Fax No.: 02 12345678
Fax Subject: My Test Subject Here
Recipient Name: Joe Blogs
The command line would look like this but it would all be on one line without the \

C:\windows\System32\cscript.exe \
"D:\fthome\custom\bin\send_fax.vbs" \
"D:\fthome\v7\DelTemp\fts9CB02.tif" "02 12345678" "My Test Subject Here" "Joe Blogs"

'for x = 0 to wscript.arguments.count - 1
'	if wscript.arguments(x) = "" then wscript.quit(0)
'next


if wscript.arguments.count <> 4 then
	wscript.echo "Usage: send_fax.vbs tiff_file recipient_fax_number subject recipient_name"
	wscript.quit 1
end if

set oShell = Wscript.CreateObject("WScript.Shell")

fax_file = wscript.arguments(0)
fax_recipient = wscript.arguments(1)
fax_subject =  wscript.arguments(2)
fax_recipient_name =  wscript.arguments(3)
fax_server = "your_windows_fax_server_here"
fax_sender_email = "your_address@example.com" 
fax_sender_name = "your_address_description" 
fax_sender_fax_number = "0212345678"


oShell.LogEvent	0, "File: " & fax_file & vbcrlf & "Recipient Fax No.: " & fax_recipient & vbcrlf & "Fax Subject: " & fax_subject & vbcrlf & _
							"Recipient Name: " & fax_recipient_name

Sub CheckError(strDetails) 
   Dim strErr 
   If Err.Number <> 0 then 
     strErr = strDetails & " : Exception " & Err.Description & " err.Number=0x" & Hex(Err.Number) 
     WScript.Echo strErr 
     WScript.Quit(Err.Number) 
   End If 
End Sub 

On Error Resume Next 
Set FaxServer = WScript.CreateObject("FAXCOMEX.FaxServer") 
CheckError("WScript.CreateObject(FAXCOMEX.FaxServer)") 
WScript.Echo "FaxServer created" 
'    Connect to the fax server. Specify computer name if the server is remote. See How to connect to a remote Fax Service for details. 
FaxServer.Connect fax_server
CheckError("FaxServer.Connect") 

Set FaxDoc = WScript.CreateObject("FAXCOMEX.FaxDocument") 
CheckError("WScript.CreateObject(FAXCOMEX.FaxDocument)") 

'    Set file name of any printable document. 
FaxDoc.Body = fax_file
CheckError("FaxDoc.Body") 
FaxDoc.DocumentName = fax_subject 
FaxDoc.Subject = fax_subject

'    Add recipient's fax number. If this string contains a canonical fax number 
'    (starting with plus + followed by a country code, an area code in round brackets 
'    surrounded by spaces and a fax number), the Fax Service will translate 
'    that number into dialable format in accordance with your current location. 
'    Otherwise, make sure the international prefix or long distance prefix is specified when needed, 
'    as the fax number will be passed on to a fax driver (Fax Service Provider) unchanged. 
'    For example, sending a fax from San Francisco to Sydney's fax number 123456, the canonical address 
'    +61 (2) 123456 will be translated into dialable address 011612123456. 
'    If you are using T37FSP in conjunction with Internet Fax Service, specify absolute address 
'    612123456 (without leading plus, to avoid translation into dialable format), 
'    as most Internet Fax Services expect the number in the absolute format. 
'    To take advantage of Windows Fax Service outbound routing available on Windows Server 
'    fax address must be specified in canonical format. 

Set FaxRecipient = FaxDoc.Recipients.Add(fax_recipient)
FaxRecipient.FaxNumber = fax_recipient
FaxRecipient.Name = fax_recipient_name

'    Optionally, set the sender properties. 
'    T37FSP uses only FaxDoc.Sender.Email in Windows Server 2003 for delivery status notifications. 
'    In Windows Server 2008, T37FSP derives email address from FaxDoc.Sender.Name via facsBridge.xml file. 

FaxDoc.Sender.Email = fax_sender_email 
FaxDoc.Sender.Name = fax_sender_name 
FaxDoc.Sender.FaxNumber = fax_sender_fax_number

'    Optionally, Use FaxDoc.CoverPage and FaxDoc.CoverPageType to specify a cover page 
'    FaxDoc.CoverPage = generic 
'    FaxDoc.CoverPageType = 2 

'    Optionally, you can control banner in outbound faxes 
FaxServer.Folders.OutgoingQueue.Branding = False '    True to set banner on, False to set banner off 
FaxServer.Folders.OutgoingQueue.Save '      Make the change persistent 
'    Optionally, use FaxServer.Folders.OutgoingQueue.Retries and 
'    FaxServer.Folders.OutgoingQueue.RetryDelay to control retries 

'    Submit the document to the connected fax server and get back the job ID. 
JobID = FaxDoc.ConnectedSubmit(FaxServer) 
CheckError("FaxDoc.ConnectedSubmit") 
WScript.Echo "FaxDoc.ConnectedSubmit success" 


0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...