Wiki Home

Tapi Fax Automation


Namespace: Wiki
How to send a Fax on Any Windows machine ;)

Okay, any Win2000 machine with the "Windows NT Fax Driver" installed (which I believe is in the default Win2k installation). The documentation I went by in the MSDN library, ( \Platform SDK\Networking and Directory Services\Network Communication\Fax Service\Fax Service Client API Reference\Fax Service Client API Visual Basic Reference) however, describes this as the standard TAPI interface; so it likely works in Win NT, Win98 and maybe Win95, if you have the right Windows fax software installed)

For simplicity, this example sends a word document with no cover page as a fax, using the current machine as the fax server. This would, with little effort, be able to send a fax using a different machine as a fax server, and with some more effort, be able to originate the fax document as printing from VFP (but, then, why not just use automation to produce your fax in Word from within VFP?).

x=createobject('faxserver.faxserver')
*lcNetInfo = SYS(0)
*lcMachine ='\\'+alltrim( Left( lcNetInfo, AT('#', lcNetInfo )-1 ) )
lcMachine = "\\"+GETWORDNUM(SYS(0),1)   && somewhat simpler code; wOOdy
x.connect( lcMachine )
fj = x.getjobs()
?fj.count  && Prints "0"
fj=.f.
* Show the fax drivers loaded on this machine:
fp = x.getports()
?fp.count
?fp.item(1).name
?fp.item(1).canmodify
?fp.item(1).rings
?fp.item(1).send
?fp.item(1).tsid
?fp.item(1).csid

* Create a fax document
FD = x.createdocument("filename")
fd.faxnumber = '687-9870'
fd.displayname = 'VFP Fax Message'
* Before running this program, create a word document
*   called SampleFax.doc... The TAPI interface will automatically
*   invoke the registered shell "Print" command on it.
fd.filename = fullpath("samplefax.doc")
fd.sendcoverpage = .f.

* Send it Off!
* (you should see Word open briefly and print the document,
*   then the Microsoft Fax icon should show up in the system tray
*   and try to send the fax!)
fd.Send

*clean up  (probably should wait a bit before this)
inkey(1)
fd = .f.
x  = .f.

Contributors: wgcs
Question - on XP Pro w sp2 installed it fails on line 5 (fj = x.getjobs() )
and other parts of this fail too with an OLE error. Could it be a rights or security issue?
Anyone got this to work with XP Pro SP2 ? [answering my own question - add SET OLEOBJECT ON to the top of this code William Sanders]

This code worked for me using a USR modem on my XP PC.
I've also included a link to the MSDN website and the original VB example...

Hope this helps...
Derek Jackson


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

SET OLEOBJECT ON

FaxServer=createobject('FAXCOMEX.FaxServer')
FaxDoc = Create Object("FAXCOMEX.FaxDocument")


FaxServer.Connect('') &&name of the fax server or blank for local PC


&&Check if the service is busy...
IF FaxServer.activity.OutgoingMessages>0
MESSAGEBOX("Fax service is busy. Please try Later",48,"Busy")
RETURN .F.
ENDIF

FaxDoc.body="c:\docs\po12345.pdf" &&The document itself
FaxDoc.DocumentName = "automated fax"
FaxDoc.Recipients.add(1)
FaxDoc.Recipients.item(1).name="First Guy"
FaxDoc.Recipients.item(1).FaxNumber="080012345"
FaxDoc.Recipients.add(2)
FaxDoc.Recipients.item(2).name="Second Guy"
FaxDoc.Recipients.item(2).FaxNumber="080054321"

FaxDoc.coverpagetype=1 &&1 is local
FaxDoc.CoverPage="FullPath ... \confdent.cov" &&enter the full path to the COV file
FaxDoc.Sender.Email = ""
FaxDoc.Sender.Name = "My NAme"
FaxDoc.subject="Automated Fax Purchase Order"
FaxDoc.Sender.FaxNumber = "+44(0)1234xxxyyy"
FaxDoc.ReceiptType = 0
FaxDoc.ReceiptAddress = ""
FaxDoc.AttachFaxToReceipt = .F.

JobID = FaxDoc.ConnectedSubmit(FaxServer)

DO CASE
CASE TYPE("JobID")!="C"
MESSAGEBOX("FAX NOT SUBMITTED FOR SENDING!",48,"Fax Failure")
llRetVal=.F.
CASE ALEN(JobID,1)=FaxDoc.Recipients.count
MESSAGEBOX(ALLTRIM(STR(ALEN(JobID,1)))+" Job"+IIF(ALEN(JobID,1)>1,"s","")+" submitted for sending",48,"Fax submitted for sending")
llRetVal=.T.
CASE ALEN(JobID,1)!=FaxDoc.Recipients.count
MESSAGEBOX("Failed to submit the correct number of fax jobs to the server"+CHR(13)+"Some recipients may not receive your fax",48,"Incorrect number of jobs submitted")
llRetVal=.F.
OTHERWISE
MESSAGEBOX("Unknown error"+CHR(13)+"Some recipients may not receive your fax",48,"Unknown Error")
llRetVal=.F.
ENDCASE


RETURN llRetVal




************************************************************************************
&&http://msdn.microsoft.com/en-us/library/ms692936(VS.85).aspx


*!* 'Connect to the fax server
*!* objFaxServer.Connect ""

*!* 'Set the fax body
*!* objFaxDocument.Body = "c:\Docs\Body.txt"

*!* 'Name the document
*!* objFaxDocument.DocumentName = "My First Fax"

*!* 'Set the fax priority
*!* objFaxDocument.Priority = fptHIGH

*!* 'Add the recipient with the fax number 12225550100
*!* objFaxDocument.Recipients.Add "12225550100", "Bud"

*!* 'Choose to attach the fax to the fax receipt
*!* objFaxDocument.AttachFaxToReceipt = True

*!* 'Set the cover page type and the path to the cover page
*!* objFaxDocument.CoverPageType = fcptSERVER
*!* objFaxDocument.CoverPage = "generic"

*!* 'Provide the cover page note
*!* objFaxDocument.Note = "Here is the info you requested"

*!* 'Provide the address for the fax receipt
*!* objFaxDocument.ReceiptAddress = "someone@example.com"

*!* 'Set the receipt type to email
*!* objFaxDocument.ReceiptType = frtMAIL

*!* 'Specify that the fax is to be sent at a particular time
*!* objFaxDocument.ScheduleType = fstSPECIFIC_TIME
*!* 'CDate converts the time to the Date data type
*!* objFaxDocument.ScheduleTime = CDate("4:35:47 PM")

*!* objFaxDocument.Subject = "Today's fax"

*!* 'Set the sender properties.
*!* objFaxDocument.Sender.Title = "Mr."
*!* objFaxDocument.Sender.Name = "Bob"
*!* objFaxDocument.Sender.City = "Cleveland Heights"
*!* objFaxDocument.Sender.State = "Ohio"
*!* objFaxDocument.Sender.Company = "Microsoft"
*!* objFaxDocument.Sender.Country = "USA"
*!* objFaxDocument.Sender.Email = "someone@microsoft.com"
*!* objFaxDocument.Sender.FaxNumber = "12165555554"
*!* objFaxDocument.Sender.HomePhone = "12165555555"
*!* objFaxDocument.Sender.OfficeLocation = "Downtown"
*!* objFaxDocument.Sender.OfficePhone = "12165555553"
*!* objFaxDocument.Sender.StreetAddress = "123 Main Street"
*!* objFaxDocument.Sender.TSID = "Office fax machine"
*!* objFaxDocument.Sender.ZipCode = "44118"
*!* objFaxDocument.Sender.BillingCode = "23A54"
*!* objFaxDocument.Sender.Department = "Accts Payable"

*!* 'Save sender information as default
*!* objFaxDocument.Sender.SaveDefaultSender

*!* 'Submit the document to the connected fax server
*!* 'and get back the job ID.

*!* JobID = objFaxDocument.ConnectedSubmit(objFaxServer)

*!* MsgBox "The Job ID is :" & JobID(0)

*!* objFaxServer.Disconnect

*!* Exit Sub

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<









Category Automation
( Topic last updated: 2008.12.02 08:25:09 AM )