Sending fax using VB

Posted on 2007-07-29
Medium Priority
Last Modified: 2013-12-26
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


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.AttachmentPathName = File_To_Send
MAPIMessages1.Send False

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?
Question by:raj_nbr
  • 8
  • 5
LVL 25

Expert Comment

by:Ron Malmstead
ID: 19595102
Works with microsoft shared fax printer.


'For Windows XP


Set FaxServer = 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 ""


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


'    Set file name of any printable document.

FaxDoc.Body = "test.rtf"


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)


WScript.Echo "FaxDoc.ConnectedSubmit success"

Author Comment

ID: 19598231
Does this require .NET framework?

Expert Comment

ID: 19628811
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")

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.

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 19629060
What scripting library is to be used for wscript?

Expert Comment

ID: 19629068
You dont need wsript
CreateObject on its own works

Author Comment

ID: 19634194
It doesn't work. It requires references.

Author Comment

ID: 19652400
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.....

Author Comment

ID: 19652472
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?

Author Comment

ID: 19652487
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 !

Expert Comment

ID: 19672283
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.

Author Comment

ID: 19673793
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 ?


Expert Comment

ID: 19674240
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.

Author Comment

ID: 19731937
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 ...


Accepted Solution

tonym001 earned 2000 total points
ID: 19762119
Firstly, I only mentioned Windows 98 because you mentioned you installed from the 95 CD

You dont have to include any references to the dll's. The createobject call uses the dll installed on the OS. You do, however, need a routine to detect which version of the OS is installed so you can create the appropriate fax object (Google it there are lots of examples out there)

The Fax service is available for 2000 & 2003 as I have said above. It is not installed as default, however,  so will probably have to installed from the appropriate Windows XX CD

I have not tried Vista yet - I will leave that to you :o)


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question