|
|
|||
www.capesoft.com |
|||
![]() |
Microsoft Outlook Functionality |
Office Inside provides a set of templates and objects that makes interfacing and exchanging data with Microsoft Outlook easy. With Office Inside you can easily:
One of the best ways to get acquainted with Office Inside in general, and the Outlook functionality in particular is the main Office Inside example application. This demonstrates the basic functionality that you would typically add to your application, such retrieving, updating, inserting and deleting Mail, Contacts, Tasks and Calendar entries from Outlook.
Outlook functionality falls into four separate sections:
Office Inside provides functions to very simply handle each of these categories, all of which is demonstrated in the Quick Start below!
![]()
The classes are much less intimidating than they look, a quick useful application can be built in a few minutes, without a huge amount of effort:
Now we will look at how to access the various types of data provided by Outlook in each of the QuickStart Guides below.
MailFolders
queue(oioFolderNameQType)
end
MailMessages queue(oioFolderItemsQType)
end
curFolder long
curMail long
messageHtml
&string
messageText &string
retVal long
AttachmentsQ queue(oioAttachmentsQ)
end
code
!--- First Fetch a list of all Mail folders
MyOutlook.GetMailFoldersQ(MailFolders)
messageText &= new string(32000)
messageHtml &= new string(64000)
!--- Now loop through the queue and fetch the mail items
loop curFolder = 1 to
Records(MailFolders)
Get(MailFolders, curFolder)
MyOutlook.GetMailItemsQ(MailMessages, MailFolders.EntryID)
!--- You can now loop through the MailMessages queue to retrieve each message using
! The GetEmailBody() method to get the body of the mail and the
! GetMailAttachmentsQ() to get a list of all attachments
loop
curMail = 1 to Records(MailMessages)
Get(MailMessages, curMail)
retVal = MyOutlook.GetEmailBody(MailMessages.EntryID, messageText,
false)
if
retVal = -1
! An error occured, the COM interface failed to fetch the data
elsif
retVal > 0
! The emailText string was too small, so it was truncated, resize and fetch again
Dispose(messageText)
messageText&= new string(retVal)
retVal = GetEmailBody(MailMessages.EntryID, messageText,
false)
if retVal <> 0
! Failed to fetch the message body.
end
end
retVal = MyOutlook.GetEmailBody(MailMessages.EntryID, messageHtml,
true)
! Handle errors and resizing here in the same fashion as above
myOutlook.GetMailAttachmetsQ(AttachmentsQ, MailMessages.EntryID)
!--- This is where you would store or process the contents of the message, the attachments etc.
! for example you can call the SaveAttachment()method to save the attachments to disk.
! See the section below for more information on Attachment Handling
end
end
Free(MailFolders)
Free(MailMessages)
Dispose(messageText)
Dispose(messageHtml)
You can fetch a list of all attachments for a particular Mail message using the GetMailFoldersQ() method, which takes a oioAttachmentsQ queue and populates it with a list of all attachments for a particular mail:
AttachmentsQ
queue(oioAttachmentsQ)
end
i
long
savePath
string(File:MaxFileName)
code
MyOutlook.GetMailAttachmetsQ(AttachmentsQ, MailMessages.EntryID)
savePath = LongPath() & '\Attachments\'
!--- Save All Attachments
MyOutlook.SaveAtttachment(MailMessages.EntryID, 0, savePath, AttachmentsQ.FileName)
!--- Can also save individual attachments, for example save attachments that are not EXEs:
loop i = 1
to Records(AttachmentsQ)
Get(AttachmentsQ, i)
if not Instring('.exe',
Lower(AttachmentQ.FileName), 1, 1)
MyOutlook.SaveAtttachment(MailMessages.EntryID, AttachmentsQ._Index,
|
savePath, AttachmentsQ.FileName)
end
end
Free(MailAttachments)
Sending Mail
There are two ways of sending mail provided by Office Inside:
While call oi_SendMail makes sending mail simple, becuase
it creates and destroy the oiOutlook object, and does the initialisation
each time that it is called, it should not be used to send multiple
messages. Call oi_SendMail where you just need to send a single, occational
message. For sending a number of mail messages, or a batch of mail
etc. the SendMail() method is a better alternative.
Contacts, Tasks and Appointments are all managed in a very similar manner. The following methods are used to manage the various entries:
As you can see above, for fetching entries there are two approachs:
Example Code for Option 1: Fetching (and updating) specific entries using the class properties.
code
! Get a specific task by EntryID
myOutlook.GetTask(TaskEntryID)
! Delete the task if it has passed it's due date
if Today() > myOutlook.TaskProperties.StartDate_Date
and |
Clock() > myOutlook.TaskProperties.StartDate_Time
myOutlook.DeleteTask(TaskEntryID)
else
! The properties can also be modified and the Task entry updated
myOutlook.TaskProperties.Subject = 'Soccer Ball Collection'
myOutlook.TaskProperties.Body = 'Collect new soccer balls from supplier'
! oio:ImportanceHigh or oio:ImportanceNormal or oio:ImportanceLow
myOutlook.TaskProperties.Importance = oio:ImportanceHigh
myOutlook.TaskProperties.StartDate_Date = Date(12, 10, 2007)
! Set the time to 15h30, 3:30PM
myOutlook.TaskProperties.StartDate_Time = (15*60 + 30)*6000
myOutlook.TaskProperties.ReminderSet = true
myOutlook.TaskProperties.ReminderTime_Date =
Date(12, 10, 2007)
! Reminder an hour before the event at 2:30PM (14h30)
myOutlook.TaskProperties.ReminderTime_Time = (14*60 + 30)*6000
myOutlook.TaskProperties.ReminderPlaySound =
true
myOutlook.TaskProperties.ReminderSoundFile = '.\Reminder.wav'
myOutlook.TaskProperties.LastModificationTime_Date =
Today()
myOutlook.TaskProperties.LastModificationTime_Time =
Clock()
myOutlook.UpdateTask(TaskEntryID)
end
Example Code for Option 2: Fetching all entries using the queue types.
MyCalendar
queue(oioCalendarQType1)
end
MyEvents
queue(oioCalendarQType1)
end
code
!--- Fill a queue with all Calendar entries
MyOutlook.GetAppointmentsQ(MyCalendar)
loop i = 1
to Records(MyCalendar)
Get(MyCalendar, i)
! The queue fields contain the information for this
! Appointment (calendar entry):
! Example: All recurring events could be added to another queue
if
MyCalendar.IsRecurring
MyEvents = MyCalendar
Add(MyEvents)
else
! Example: All expired, non recurring entries could be deleted
if Today() > MyCalendar.End_Date and
Clock() > MyCalendar.End_Time
MyOutlook.DeleteAppointment(MyCalendar.EntryID)
Delete(MyCalendar)
end
end
end
See the documentation for the following methods for more examples and information:
The examples demonstrate everything used in the QuickStart guide and much, much more. The main example is a great place to get acquainted with the functionality of Office Inside and the Outlook classes. We highly recommend it as a "first stop", a great deal of the code that you need already exists in the example application, and it demonstrates how the objects are most commonly used, as well as provides a good foundation for copying-and-pasting code into your own application to get started.
You can find the examples in your Clarion\3rdparty\Examples\Office\ folder. The main example is the Demo example, which demonstrates all the core functionality of Office Inside. In particular the Clarion 6 version demonstrates all the latest and greatest features and additions, as well as some Clarion 6 specific functionality.
| Template : Add_MSOutlook_Object | |||
| Summary | |||
|
|||
| What does it do? | |||
| This template is used
to add MS Outlook functionality to a procedure in your app. |
|||
| Prerequisites | |||
| You need to have added
the Activate_Office_Inside
global extension template before you can add this template to a procedure. |
|||
| How do I implement it? | |||
|
|||
|
What are my options? |
|||
|
|
General Tab: Object Name: This is the name of the Office Inside object that this template will create and implement. Typically this would default to 'MyOutlook1', but you can change it if you would prefer to call the object something else.
Base1 Tab: Initialise This Object: This option allows you to select whether the template will generate code to initialise the object and when it will be initialised. Event Handler: When the Init() method is called it can optionally turn on event handling. This option allow this to be controlled from the template. Base2 Tab: Kill This Object: The dropdown allows you to choose whether code is generated to Kill() the Outlook object (and close Outlook), as well as when that code should be called.
|
||
This section describes the various classes which make up "Office Inside". Each class contains methods and properties, which are documented below. Each method is documented by giving the method name, the parameters, an example of how to code the method, a list describing what the method does, and additional comments below.
The oiOutlook class is a "wrapper" class, which is used by the templates and by other classes as the "communication" layer between Office Inside and MS Outlook. Should you wish to write code which communicates "directly" with MS Outlook, this is the class you're looking for.
The table below lists methods grouped by usage rather than in alphabetical order. For example all methods for handling mail are grouped together, all methods for handling contacts are groups together and so on. This is a good place to start if you know what you need to do, but aren't sure what to use to do it.
For an alphabetical listing of the class methods, see the next section - The oiOutlook Class - Alphabetical Listing of Methods.
| oiOutlook Class Methods - Grouped by Use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The table below list the same class methods as above, but in alphabetical order.
| oiOutlook Class Methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This section describes each method listed above, how it is used, the parameters, return values, date types and related properties of the class that the object uses. In addition each method has an example of using the method, along with a list of related methods in the "See Also" section. Where the method uses specific data types they are listed along with the method, and each field described where applicable.
| DeleteAppointment (string pEntryID)
Parameters
Return Values
Examples !--- Example 1: Simply Delete an Appointment using the EntryID to identify it:
MyOutlook.DeleteAppointment(EntryID)
!--- Example 2: Fetch all appointments, and delete all non-recurring ! appointments that have expired (already occurred) MyCalendar queue(oioCalendarQType1) end code See Also
|
|
DeleteContact (string pEntryID) Deletes a Contact (Address Book Entry) from Outlook when passed the unique EntryID that Outlook uses to identify the specific contact. Note: This method does not prompt the user with a "are you sure you want to delete this record" message, you need to do that yourself if you want to, this method simply deletes the Contact from Outlook. Parameters string pEntryID: The unique identifier used by Outlook for this entry. The EntryID is retrieved when calling GetContact() or GetContactsQ() and is also returned when you add a new entry by calling the InsertContact() method. Return Values Returns 1 for success, or zero for failure. Examples EditContact_EntryID string(255) See Also InsertContact, GetContact, GetContactsQ
|
|
DeleteTask (string pEntryID) Deletes the task identified by the pEntryID parameter from Outlook. Note: This method does not prompt the user with a "are you sure you want to delete this record" message, you need to do that yourself if you want to, this method simply deletes the Task from Outlook. Parameters string pEntryID: The unique identifier used by Outlook for this entry. The EntryID is retrieved when calling GetTask() or GetTasksQ() and is also returned when you add a new entry by calling the InsertTask() method. Return Values Returns 1 for success and zero for failure Examples !--- Fetch all Task, and delete all Tasks that are ! older than the current date and time TasksQ queue(oioTaskQType1) end code MyOutlook.GetTasksQ(TasksQ) loop i = 1 to Records(TasksQ) Get(TasksQ, i) if (Today() > TasksQ.StartDate_Date and Clock() > TasksQ.StartDate_Time) MyOutlook.DeleteTask(TasksQ.EntryID) Delete(TasksQ) end end See Also
|
|
DisplayContact (string pEntryID) Displays the Contact with the passed EntryID in Outlook. This opens the Outlook Contact dialog, allowing the user to view and modify the Contact using the Outlook dialog itself. Parameters string pEntryID: The unique identifier used by Outlook for this entry. The EntryID is retrieved when calling GetTask() or GetTasksQ() and is also returned when you add a new entry by calling the InsertTask() method. Return Values Returns 1 for success and zero for failure Examples if EditContact_EntryID = '' Message('Please select a Contact first...', 'Office Inside') else if MyOutlook1.DisplayContact(EditContact_EntryID) = false Message('Failed to display the Contact!', 'OfficeInside') end end See Also GetTask, GetTasksQ, InsertTask
|
|
ErrorTrap (string pErrorString, string pFunctionName) This method is called when an error occurs. Office Inside provides embed points for this method (before parent call, and after parent call) where you can put code to deal with any errors Office Inside experiences (see the example code below - note that the text on a grey background is what the template generates, and the code after the parent call is an example of custom error handling). By default any errors that Office Inside encounters will be dealt with as follows:
Note 1: Even if you suppress error messages the ErrorTrap method will still be called. Note 2: The Suppress Error Messages checkbox simply generates a line of code that sets the SuppressErrorMessages property to true. You can set this property manually if you prefer. Parameters string pErrorString: A string containing the error message that the method passed to ErrorTrap. You can use this string to display the error to the user, and also to implement your own error handling based on which error occurred. string pFunctionName: A string that contains the name of the Office Inside method that the error occured in. Return Values None. ErrorTrap is called by the class itself, typically it is only called by the class itself and you would embed code in it, but not call it yourself. Examples
MyOutlook.ErrorTrap PROCEDURE(string pErrorString, string pFunctionName) See Also
|
|
This event callback method is fired when Outlook sends an item (a Mail Message). You can use this event callback method to add code to perform some action (such as informing the user) when a send occurs. This is a virtual method, which will fire automatically when the event occurs. Microsoft Office fires this event, which in turn is picked up inside the Office Inside DLL, which in turn calls this method in your code. Simply embed code in the provided embed point to deal with this event (if you wish to do so). Parameters None Return Values None Examples MyOutlook.EventItemSend PROCEDURE()
code MessageStore.Sent = true ! Update a record's sent status Access:MessageStore.Update() See Also EventItemSend, EventNewMail, EventOptionsPagesAdd, EventQuit, EventReminder, EventStartup
|
|
EventNewMail () This event callback method is fired when a new Mail Message is created in Outlook. You can use this event callback method to add code to perform some action (such as informing the user) when a new mail message is added to Outlook. This is a virtual method, which will fire automatically when the event occurs. Microsoft Office fires this event, which in turn is picked up inside the Office Inside DLL, which in turn calls this method in your code. Simply embed code in the provided embed point to deal with this event (if you wish to do so). Parameters None Return Values None Examples MyOutlook.EventItemSend PROCEDURE() code MessageStore.Sent = true ! Update a record's sent status Access:MessageStore.Update() See Also:
|
|
This event callback method is called when the Options page (window) in Office is displayed. You can use this (and the other Event methods) to trap when this even occurs are respond to it in your code. This is a virtual method, which will fire automatically when the event occurs. Microsoft Office fires this event, which in turn is picked up inside the Office Inside DLL, which in turn calls this method in your code. Simply embed code in the provided embed point to deal with this event (if you wish to do so). Parameters None Return Values None Examples MyOutlook.EventOptionsPagesAdd
PROCEDURE()
See Also EventItemSend, EventNewMail, EventOptionsPagesAdd, EventQuit, EventReminder, EventStartup
|
|
EventQuit () This event callback method is fired when the user exits Outlook that the oiOutlook started. This is a virtual method, which will fire automatically when the event occurs. Microsoft Office fires this event, which in turn is picked up inside the Office Inside DLL, which in turn calls this method in your code. Simply embed code in the provided embed point to deal with this event (if you wish to do so). Parameters None Return Values None Examples MyOutlook.EventQuit PROCEDURE()
See Also EventItemSend, EventNewMail, EventOptionsPagesAdd, EventQuit, EventReminder, EventStartup
|
|
This event callback method is called when Outlook triggers a Reminder for a task. Reminders can display a message to the user, or play a sound to inform the user that their is a pending task. This is a virtual method, which will fire automatically when the event occurs. Microsoft Office fires this event, which in turn is picked up inside the Office Inside DLL, which in turn calls this method in your code. Simply embed code in the provided embed point to deal with this event (if you wish to do so). Parameters None Return Values None Examples MyOutlook.EventReminder PROCEDURE() See Also EventItemSend, EventNewMail, EventOptionsPagesAdd, EventQuit, EventReminder, EventStartup
|
|
EventStartup () This event callback method is called when Outlook starts up. You can use this method to execute any code that you want to happen the Outlook has first started. This is a virtual method, which will fire automatically when the event occurs. Microsoft Office fires this event, which in turn is picked up inside the Office Inside DLL, which in turn calls this method in your code. Simply embed code in the provided embed point to deal with this event (if you wish to do so). Parameters None Return Values None Examples MyOutlook.EventStartup PROCEDURE() See Also EventItemSend, EventNewMail, EventOptionsPagesAdd, EventQuit, EventReminder, EventStartup
|
|
GetAppointment (string pEntryID) Whereas the GetAppointmentsQ method is used to read all appointments from Outlook into a Clarion queue, the GetAppointment method can be used to read a single appointment record, if you know its Outlook ID (which you pass as pEntryID)
Note: Recurring Appointments
Parameters string pEntryID: The Unique identifier that Outlook uses for this entry. This value is retrieved when calling InsertAppointment, and the EntryID field in the the queue is populated with this value when calling GetAppointmentsQ. Return Values Returns 1 for success and zero for failure. Examples This example gets an appointment and then deletes it if is it older than today's date and time. code
MyOutlook.GetAppointment(appointmentID) ! Fetch an appointment
if Today() > MyOutlook.AppointmentProperties.End_Date and |
Clock() > MyOutlook.AppointmentProperties.End_Time
MyOutlook.DeleteAppointment(MyOutlook.AppointmentProperties.EntryID)
end
Object Properties This method populates the oiOutlook.AppointmentProperties member of the oiOutlook object with the details of the Appointment. AppointmentProperties is a group with the following fields:
See Also InsertAppointment, GetAppointmentsQ, DeleteAppointment, UpdateAppointment
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
GetAppointmentsQ (*oioCalendarQType1 pQueue, <string pEntryID>) This method is used to read appointments from Outlook, by filling a Clarion queue (as in the example code below). The queue filled is a oioCalendarQType1 queue. See Data Types below for a list of all fields in the queue and a description of each field and it's values. Note: You should declare the queue using the type provided by Office Inside, as these queues may change in structure with additional field in future versions, and using the Type rather than redeclaring the queue ensures you maintain compatibility.
Note: Recurring Appointments
Parameters *oioCalendarQType1 pQueue: A queue that is filled with the Appointments from Outlook. See the Data Types section below for a full description of the oioCalendarQType1 queue type, the fields that it contains and a description of each field and its values. <string pEntryID>: An optional string that fills the queue with a single entry containing the Appointment that matches the passed EntryID. To retrieve a single record we recommend using the GetAppointment method instead. Return Value Returns 1 for success and zero for failure. Examples ! This example fills a queue with all Appointments, then adds all ! recurring appointments to a new queue (MyEvents). It also deletes ! all appointments that are not recurring and where the appointment end ! date and time are older than today MyCalendar queue(oioCalendarQType1) end MyEvents queue(oioCalendarQType1) end code !--- Fill a queue with all Calendar entries MyOutlook.GetAppointmentsQ(MyCalendar) loop i = 1 to Records(MyCalendar) Get(MyCalendar, i) ! The queue fields contain the information for this Appointment (calendar entry) ! Example: Add recurring events to another queue if MyCalendar.IsRecurring MyEvents = MyCalendar Add(MyEvents) else ! Example: All expired, non recurring entries could be deleted if Today() > MyCalendar.End_Date and Clock() > MyCalendar.End_Time MyOutlook.DeleteAppointment(MyCalendar.EntryID) Delete(MyCalendar) end end end Data Types
See Also InsertAppointment,
GetAppointment,
DeleteAppointment,
UpdateAppointment
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
GetContact (string pEntryID) Retrieves a specific contact using the passed EntryID. Whereas the GetContactsQ method is used to read all contacts from Outlook into a Clarion queue, the GetContact method can be used to read a single contact record, if you know its Outloo |