General programming tasks
Log on
This will log on to the server named lemur with an
account name and password of guest. The beginning of all
your programs should create the object and login.
' create the FaxSession object
Set objFaxSession = CreateObject("facsys.faxsession")
' log on to Facsys server
objFaxSession.logon "lemur", "guest", "guest"
back to categories list
Log off
This will log off the server. Before your program exists,
you should also dispose of the FaxSession object.
' log off Facsys server
objFaxSession.logoff
' clean up
Set objFaxSession = Nothing
back to categories list
Working with messages
Accessing messages
Messages are stored in a collection with-in a folder. The
folowing enumerates the messages collection in the Outbox
folder.
' get the messages collection for the Outbox folder
Set objMsgs = objFaxSession.GetFolder(FaxMsg_Folder_Outbox).Messages
' loop through the messages collection
msgCount = objMsgs.Count
For i = 1 to msgCount
' the current message is now objMsgs(i)
Next
' clean up
Set objMsgs = Nothing
back to categories list
Sorting messages
You can sort messages and have the server remember the
setting for the folder by setting the SortProperty and
SortOrder on the folder object before accessing the messages
collection. This example will sort the messages in the
outbox in ascending order based on the subject field the
next time a message collection is created.
' get the Outbox folder
Set objFldr = objFaxSession.GetFolder(FaxMsg_Folder_Outbox)
' set the sort order & field property to sort on
objFldr.SortOrder = FaxMsg_Sort_Ascending
objFldr.SortProperty = FaxMsg_MSG_SUBJECT
' get the sorted messages collection
Set objMsgs = objFldr.Messages
' clean up
Set objMsgs = Nothing
Set objFldr = Nothing
Note that you can also set a secondary sort by using
SortOrder2 and SortProperty2 off the folder object.
back to categories list
Moving a message to another folder
This code will move the first message in the Outbox
folder to the Deleted Items folder. Note that moving to the
deleted items folder is a special case that will
automatically cancel the messages. It is up to the
application to actually delete the messages from the Deleted
Items folder later.
' get the first message from the Outbox folder
Set objMsg = objFaxSession.GetFolder(FaxMsg_Folder_Outbox).Messages(1)
' move the message to the deleted items folder
objMsg.MoveTo(FaxMsg_Folder_DeletedItems)
' clean up
Set objMsg = Nothing
back to categories list
Deleting a message
This code will delete the first message in the Deleted
Items folder.
' get the first message from the Deleted Items folder
Set objMsg = objFaxSession.GetFolder(FaxMsg_Folder_DeletedItems).Messages(1)
' delete the message
objMsg.Delete
' clean up
Set objMsg = Nothing
This code will delete ALL the messages in the Deleted
Items folder.
' get the Deleted Items folder
Set objMsgs = objFaxSession.GetFolder(FaxMsg_Folder_DeletedItems).Messages
' move the message to the deleted items folder
objMsgs.RemoveAll
' clean up
Set objMsgs = Nothing
back to categories list
Sending a message
This block of code will create a fax message that
contains some text and two file attachments to be sent to
two recipients.
' create the new message object
Set objMsg = objFaxSession.createmessage
' set message text
objMsg.Text = "This is a test message."
' add first recipient
Set objRecip = objMsg.recipients.Add
objRecip.Name = "William McNeely"
objRecip.faxnumber = "271-0609"
' add second recipient
Set objRecip = objMsg.recipients.Add
objRecip.Name = "Dan Bachmann"
objRecip.faxnumber = "271-0908"
' add two attachments
objMsg.attachments.Add "c:\bills.xls"
objMsg.attachments.Add "c:\mybook.doc"
' send the message!
result = objMsg.send
' clean up
Set objRecip = Nothing
Set objMsg = Nothing
back to categories list
Working with folders
Accessing folders
Folders are stored in the root folder collection. The
root folder is a special folder that contains only the
folders at the root level (no messages at the root). The
folowing enumerates the root level folders.
' get the root folder's folders collection
Set objFolders = objFaxSession.RootFolder.Folders
' loop through the messages collection
folderCount = objFolders.Count
For i = 1 to folderCount
' the current folder is now objFolders(i)
Next
' clean up
Set objFolders = Nothing
back to categories list
Moving a folder to another folder
This code will move folder# 20 to the Deleted Items
folder. Note that moving to the Deleted Items folder is a
special case that will automatically cancel all messages in
the folder and subfolders being moved. It is up to the
application to actually delete the folders from the deleted
items folder later.
' get the first message from the Outbox folder
Set objFldr = objFaxSession.GetFolder(20)
' move folder to the deleted items folder
objFldr.MoveTo(FaxMsg_Folder_DeletedItems)
' clean up
Set objFldr = Nothing
back to categories list
Renaming a folder
This code will rename folder #20.
' get folder #20
Set objFldr = objFaxSession.GetFolder(20)
' rename the folder and commit the changes to the server
objFldr.Name = "New Folder Name"
objFldr.Update(TRUE)
' clean up
Set objFldr = Nothing
back to categories list
Deleting a folder
This code will delete folder #20. All of the folder's
messages will be canceled and deleted as well.
' get folder #20
Set objFldr = objFaxSession.GetFolder(20)
' delete the folder
objFldr.Delete
' clean up
Set objFldr = Nothing
This code will delete ALL the folders in folder #20 with
out deleting folder #20. All subfolders and their messages
will be deleted as well.
' get the Deleted Items folder
Set objFldrs = objFaxSession.GetFolder(20).Folders
' move the message to the deleted items folder
objFldrs.RemoveAll
' clean up
Set objFldrs = Nothing
back to categories list
Working with phonebooks
Accessing phonebooks
The FaxSession Object contains the root Phonebooks,
through which one can access all Phonebook,
PhonebookContainer, and Phonebooks Objects associated with
the user. This code will enumerate the logged in user's root
level phonebooks.
Dim objPhonebooks As IFaxPhonebooks
Set objPhonebooks = objFaxSession.Phonebooks
'loop through Phonebooks
For i = 1 to objPhonebooks.Count
'Current Phonebook is now objPhonebooks(i)
Next
'Clean up
Set objPhonebooks = Nothing
back to categories list
Accessing containers
PhoneBookContainer Objects help organize your phonebook
entries. The following code will open the first phonebook,
and enumerate its top-level phonebook containers
Dim objPhonebook As IFaxPhonebook
Dim objRootContainer As IFaxPhonebookContainer
Dim objContainer As IFaxPhonebookContainer
Set objPhonebook = objFaxSession.Phonebook(1)
Set objRootContainer = objPhonebook.RootContainer
'loop through Containers
For i = 1 to objRootContainer.Containers.Count
'Current Container is now objRootContainers.Containers(i)
Next
'clean up
Set objRootContainer As Nothing
Set objContainer As Nothing
Set objPhonebook As Nothing
back to categories list
Moving a container
This code will move Phonebook Container #20 to the Root
Container.
Dim RootContainerID As Int
' get Root Container ID
RootContainerId = objFaxSession.Phonebooks.Phonebook(1).RootContainer.ContainerID
' get the first message from the Outbox folder
Set objPhonebookContainer = objFaxSession.Phonebooks.Phonebook(1).GetContainer(20)
' move folder to the deleted items folder
objPhonebookContainer.MoveTo(RootContainerID)
' clean up
Set objPhonebookContainer = Nothing
back to categories list
Renaming a phonebook
This code will rename phonebook #1 in the root Phonebooks
collection.
' get phonebook #1
Set objPhonebook = objFaxSession.Phonebooks.Phonebook(1).
' rename the phonebook and commit the changes to the server
objPhonebook.Name = "New Phonebook Name"
objPhonebook.Update(TRUE)
' clean up
Set objPhonebook = Nothing
back to categories list
Renaming a container
This code will rename phonebook container #20.
' get container #20
Set objPhonebook = objFaxSession.Phonebooks.Phonebook(1).GetContainer(20)
' rename the container and commit the changes to the server
objPhonebookContainer.Name = "New Container Name"
objPhonebookContainer.Update(TRUE)
' clean up
Set objPhonebookContainer = Nothing
back to categories list
Deleting a container
This code will delete phonebook container #20.
' get container #20
Set objPhonebook = objFaxSession.Phonebooks.Phonebook(1).GetContainer(20)
' delete the folder and commit the changes to the server
objPhonebookContainer.Delete
' clean up
Set objPhonebookContainer = Nothing
back to categories list
Deleting a phonebook
This code will delete phonebook #1 in the root phonebook
container.
' get phonebook #1 out of the root phonebooks collection
Set objPhonebook = objFaxSession.Phonebooks.Phonebook(1)
' delete the phonebook and commit the changes to the server
objPhonebook.Delete
' clean up
Set objPhonebook = Nothing
|