Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Send a Fax Message with an Attachment Using CDO


View products that this article applies to.

This article was previously published under Q285993

↑ Back to the top


Summary

This article demonstrates how to programmatically send a fax with an attachment using Collaboration Data Objects (CDO) 1.2x.

↑ Back to the top


More information

NOTE: You must have fax capabilities through a fax gateway or on Microsoft Windows 95 or Windows 98. In general, if you can send a fax using Microsoft Outlook, you should be able to fax using this method.

The attached file must also be of a type that has a registered OLE association with an application that knows how to print the document; this is because that application will be used to render the document. For instance, a .doc file might be rendered by Microsoft Word or WordPad, a .xls file requires Excel, Notepad handles a .txt file, and so on.

To run this sample, follow these steps:
  1. Create a new Visual Basic project.
  2. On the Project menu, click References, and then select Microsoft CDO 1.21 Library.
  3. Add a button to the form and paste the following code below into the Click subroutine:
    Private Sub Command1_Click()
    
    Dim objSession 
    Dim objMessage 
    Dim objRecipient 
    
    On Error Resume Next 
    
    'Create The Session Object. 
    Set objSession = CreateObject("Mapi.Session")
    
    'Logon to Mailbox. 
    'TODO: Change the line below to represent the profile that you are using.
    objSession.Logon "<Outlook Profile Name>" 
    
    'Create the Message Object. 
    Set objMessage = objSession.Outbox.Messages.Add 
    
    If err.number <> 0 Then 
    	err.Clear 
    	MsgBox "Failed To LogOn Succesfully" 
             Exit Sub
    Else 
    	MsgBox objSession.CurrentUser & " logged on succesfully." 	
    End If 
    
    'Set up Message. 
    objMessage.Subject = "Test" 
    objMessage.Text = "This is a test" 
    
    'Create the Recipient Object. 
    set objRecipient = objMessage.Recipients.Add 
    
    'Set up Recipient. 
    'Note: For sample fax syntax, see the Knowledge Base article listed
    'later in this article. Because other third-party vendors may have a 
    'different syntax, please verify the syntax with your vendor before 
    'using this code.
    
    objRecipient.Name = "[FAX:faxnumber]" 
    objRecipient.Type = 1 
    objRecipient.Resolve 
    
    'TODO: Make sure to have a file created in the location indicated in the 
    'line below.
    objMessage.Attachments.Add "test.txt",0,  1, "C:\test.txt" 
    
    If err.number <> 0 Then 
    	MsgBox "There were errors" 
    Else 
    	MsgBox "Fax Sent!" 
    End If 
    
    
    'Send Message.          
    objMessage.Send 
    
    'Log off Session. 
    objSession.Logoff 
    
    'Destroy All Objects 
    Set objRecipient = Nothing 
    Set objMessage = Nothing 
    Set objSession = Nothing 
    End Sub
    					
  4. Run the project and click the button.

↑ Back to the top


References

For additional information on the fax syntax, click the article number below to view the article in the Microsoft Knowledge Base:
181222� OL98: (CW) How to Type a Fax Number on the To Line of a Mail Msg

↑ Back to the top


Keywords: KB285993, kbhowto

↑ Back to the top

Article Info
Article ID : 285993
Revision : 5
Created on : 7/13/2004
Published on : 7/13/2004
Exists online : False
Views : 552