Microsoft KB Archive/285993

= How To Send a Fax Message with an Attachment Using CDO =

Article ID: 285993

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.21
 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Exchange Server 5.5 Standard Edition

-



This article was previously published under Q285993



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



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:  Create a new Visual Basic project. On the Project menu, click References, and then select Microsoft CDO 1.21 Library.  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(&quot;Mapi.Session&quot;)

'Logon to Mailbox. 'TODO: Change the line below to represent the profile that you are using. objSession.Logon &quot;&quot;

'Create the Message Object. Set objMessage = objSession.Outbox.Messages.Add

If err.number <> 0 Then err.Clear MsgBox &quot;Failed To LogOn Succesfully&quot; Exit Sub Else MsgBox objSession.CurrentUser & &quot; logged on succesfully.&quot; End If

'Set up Message. objMessage.Subject = &quot;Test&quot; objMessage.Text = &quot;This is a test&quot;

'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 = &quot;[FAX:faxnumber]&quot; objRecipient.Type = 1 objRecipient.Resolve

'TODO: Make sure to have a file created in the location indicated in the 'line below. objMessage.Attachments.Add &quot;test.txt&quot;,0, 1, &quot;C:\test.txt&quot;

If err.number <> 0 Then MsgBox &quot;There were errors&quot; Else MsgBox &quot;Fax Sent!&quot; 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  Run the project and click the button.

