Link to home
Start Free TrialLog in
Avatar of raj_nbr
raj_nbr

asked on

Sending fax using VB

Sending fax using VB6


I have been looking for methods to send bulk fax from my application that I need to distribute. The solutions seem to be either of the two

1. But commercial ocx for sending fax
2. Use Mapi/outlook with microsoft fax printer or any other printer or use fax server object


The first one has some negative points.

1. Commercially available active Xs like Faxman does not Fax word documents. Most of the users want to send multipage word-document as faxes. They don't want to scan it into tiff and then send again.
2. There have been complaints that, the readability of  tiff files faxed using these controls is lower compared to readability of TIFF documents faxed by selecting print option and then printing to fax printer, in windows picture viewer
3. Some SDKs require their own fax service to be bought and installed. Other than my application, my user also has to buy  this fax service.

Second method is using MAPI/fax server object/outlook scripting

Code downloaded from sites like freevbcode and planet-source-code and even EE does not work. Run time error pops up, saying activex can't create object or send method failed etc. I have tried at least 15
sample codes. But none works correctly.

See a code below

karateka:

MapiSession1 - a mapi session activex
MAPIMessages1 - a mapi message activex
both activeX come with VISUAL STUDIO

the code:
-------------
MAPISession1.DownLoadMail = False
MAPISession1.LogonUI = True
MAPISession1.NewSession = True
MAPISession1.Action = mapSignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipType = 1
MAPIMessages1.RecipDisplayName = "[fax:"Fax Number"]"
MAPIMessages1.AddressResolveUI = False
MAPIMessages1.ResolveName
    MAPIMessages1.AttachmentPathName = File_To_Send
MAPIMessages1.Send False
MAPISession1.SignOff

In the above code , MAPIMessages1.RecipDisplayName = "[fax:"Fax Number"]" works if faxrecipient name is directly given. Otherwise, it says 'unknown recipient'
   
MAPIMessages1.RecipDisplayName ="My receipient" works, but it goes as mail
MAPIMessages1.RecipDisplayName = "[fax:'800343434']" doesnt work. Says 'unknown recipient'.

SImilarly, not a single code seems to be working correctly even though I am able to send fax using fax printer . outlook directly.

1. Is there any surefire meThod of sending fax from any machine using VB under all conditions? Does it work if MS Office is not installed?

2. Does microsoft Fax come by default with all versions of windows? If not what method can be used in VB that will work with any version of windows? ie: some thing that works with win 2000, 2003, xp etc. ?

3. Does outlook express come free with all versions of windows? Can this be used along with VB6 to have a 100 percent sure shot fax application?

4. Is there any 3rd party control that can be used to fax any document easily with good readability and automatability for bulk faxing?
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

Works with microsoft shared fax printer.

http://sandlerco.com/VBScript.htm

'For Windows XP

 

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 ""

CheckError("FaxServer.Connect")


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

CheckError("WScript.CreateObject(FAXCOMEX.FaxDocument)")



'    Set file name of any printable document.

FaxDoc.Body = "test.rtf"

CheckError("FaxDoc.Body")

FaxDoc.DocumentName = "My First Fax"


'     Add recipient's fax number. If this string contains a canonical fax number
'     (starting with plus + followed by country code, area code in round brackets and the 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 Internet Fax Service expects the number in the absolute format.


FaxDoc.Recipients.Add ("612123456")


'     Optionally, set the sender properties.
'     T37FSP uses only FaxDoc.Sender.Email in Windows Server 2003 for delivery status notifications.

FaxDoc.Sender.Email = "bob@xyz.com"

FaxDoc.Sender.Name = "Bob"

FaxDoc.Sender.FaxNumber = "7777777"


'     Optionally, you can control banner in outbound faxes
FaxServer.Folders.OutgoingQueue.Branding = True '    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"
Avatar of raj_nbr
raj_nbr

ASKER

Does this require .NET framework?
No you don't need .NET framework although you may need to install the Fax service component.

Control Panel -> Add \Remove Software -> Add/Remove Windows Components -> Fax Services
If you setting up a client off-site make sure they have the Windows XX CD to hand.

The above code works fine in XP & 2003 but not in NT or 2000 as its a different dll so instead of
Set FaxServer =CreateObject("FAXCOMEX.FaxServer")
It needs to be
Set FaxServer =CreateObject("FaxServer.FaxServer")
see
http://support.microsoft.com/kb/303647

The methods are also slightly different so the first thing you need to ascertain is the OS the software is installed on and go from there.
 


Avatar of raj_nbr

ASKER

What scripting library is to be used for wscript?
You dont need wsript
CreateObject on its own works
Avatar of raj_nbr

ASKER

It doesn't work. It requires references.
Avatar of raj_nbr

ASKER

Sorry tonym !!! It works without references !! ie : I need to remove the wscript. part. I thought you were asking me to use the sandlerco code directly. I didnt realise that u were asking me to take out the wscript part! Sorry again !


Let me check and come back to you.....
Avatar of raj_nbr

ASKER

Seems to be working in XP. Let me check again...

Meanwhile, could you comment on the usability of the above method in

1. XP
2. Windows 2000 and 2003
3. Vista
4. Win 95
5. Win 98 (still people use them !!")

If I remember right, 95 came with fax printer, 98 didnt. But we could use the 95 thing in 98 and fax witout any issues.  The fax service that came along with XP is different I suppose. Is there a fax service that is supported by windows 2000 and 2003 ?

Another interesting thing I got from ur link is that the above method doesnt support all document types. But, since I am able to print to a fax printer from ant doc type, the above method should work for all document type. right?

Secondly, what would u suggest -  going for a commercial fax component, or using faxcom dll?

Thirdly, do I need to include fax com dll? why is the code working even when I don't declare the dll file as a component that I am dependent on?
Avatar of raj_nbr

ASKER

Another thing.

The code works by executing the document handler app, and then using the print method -  Will this work for all documents? The print method may not be exposed at all !
For XP & 2003 use the CreateObject("FAXCOMEX.FaxServer") method
For Win98, NT(95)  & 2000 use the CreateObject("FaxServer.FaxServer") method
I dont know about Vista I haven't had to implement that solution yet.

If you go down the route of using a commercial fax component there are two drawbacks - it costs money and you have little control over the component you use. On the plus side it takes away the pain of having to develop the solution yourself and because Microsoft haven't bothered developing the component the fax server is pretty basic. Personally, I went for the fax printer option but its entirely down to you.

You dont need a reference to the object if you use the CreateObject method. However, the fax printer must be installed (see above)

To fax the document you need to have a program installed that can read that document. For instance, if you wish to fax a pdf document then you need Adobe Reader installed and so on.
Avatar of raj_nbr

ASKER

Thanks TONY. Guess I am closer to a solution that works on all microsoft platforms. Please clarify the following

1. If I make my package  for deployment in XP, then will the set up work in Windows 98? What dlls must be included in the setup so that it works in all platforms?

2. When you say fax printer must be installed, you mean fax service in XP/2000 and the microsoft fax option in 95 CD ? (98 doesnt have this option I guess. I remember copying it from 95 CD and using it in 98 ! ) Is this Fax service available in 2000 and 2003 ?

3. If the fax modem has a fax printer driver that can be installed on the PC (Guess all fax modems come with this utility), then , in any operating syetm, I must be able to just select the fax printer, and print a document to that printer - to fax it. Is this correct? Will this method work? Ie? if the modem has a cd that installs a fax printer for all os, then,  in VB, all I need to do is, send the doc to that printer , regardless of the document type. It is the fax-printer's job to convert it into TIFF and send it. Can I use this method ?

.
Hi raj

No offence but instead of reading the latest comments could you re-read my comments in this thread - all questions are answered.

 If you are looking to distribute a solution then you just have to specify a minimum spec (forget the guy on W98 - he's atypical and should be ignored).

DO NOT TRY TO PRINT A DOCUMENT TO THE FAX PRINTER IN CODE - it cannot be done as you lose control of the application when the Fax window appears.
Avatar of raj_nbr

ASKER

Not offended but shameful about not still being able to understand the key points !!

I understood the folowing :
For XP & 2003 use the CreateObject("FAXCOMEX.FaxServer") method
For Win98, NT(95)  & 2000 use the CreateObject("FaxServer.FaxServer") method

Now, my confusion is,

The above statement tells me that the method works in windows 98. Is correct?
Do I have to package different DLLS for xp and 2000?  I understand that, it is required to include faxcom.dll for XP and 2003, even though I can safely assume that the dll is part of the OS installation. Is this correct? For 2000 , NT and 95, will the same DLL work without any issues or do I have to include another DLL?

and lastly, the same question as before. Please clarify.

2. When you say fax printer must be installed, you mean fax service in XP/2000 and the microsoft fax option in 95 CD ? (98 doesnt have this option I guess. I remember copying it from 95 CD and using it in 98 ! ) Is this Fax service available in 2000 and 2003 ?

Would you know whether the method will work in Visa ? By any chance, did u try this after you posted last in EE in this thread?

Thanking u in advance ...

ASKER CERTIFIED SOLUTION
Avatar of tonym001
tonym001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial