0% found this document useful (0 votes)
156 views

Outlook Automation Part 2

The document discusses automating Microsoft Outlook using Visual FoxPro code. It explains how to make Outlook visible programmatically and get object references to Outlook folders like Inbox, Calendar, and Tasks. It also demonstrates how to count the number of messages and subfolders in the Inbox, obtain reminder items, and determine the number of read and unread messages. The document lists many properties and methods available on the Outlook Items collection for manipulating email messages.

Uploaded by

epalencia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

Outlook Automation Part 2

The document discusses automating Microsoft Outlook using Visual FoxPro code. It explains how to make Outlook visible programmatically and get object references to Outlook folders like Inbox, Calendar, and Tasks. It also demonstrates how to count the number of messages and subfolders in the Inbox, obtain reminder items, and determine the number of read and unread messages. The document lists many properties and methods available on the Outlook Items collection for manipulating email messages.

Uploaded by

epalencia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

OUTLOOK AUTOMATION PART 2 - www.foxite.com - The Home Of The Visual Fox...

Page 1 of 2

OUTLOOK AUTOMATION PART 2 by Simon Arnold

So how do we make Outlook Visible, like Word, Excel and the rest?
Outlook is the only one not to have a visible property. So the way we make Outlook visible is with the following code:

LOCAL loOutlook
AS Outlook.Application
LOCAL loNameSpace AS Outlook.NameSpace
LOCAL loExplorer AS Outlook.Explorer
#DEFINE olFolderDisplayNormal

loOutlook
= CREATEOBJECT('Outlook.Application')
loNameSpace = loOutlook.GetNamespace("MAPI")
loExplorer = loOutlook.Explorers.Add(loNameSpace.Folders[1],olFolderDisplayNormal)
loExplorer.Activate
The above code should open Outlook with the Outlook Today page.
Also to let you know at this point, you can make the individual folder pages visible, so for example if I wanted the Contacts Page to be visible, I can do this with the following code:

LOCAL loOutlook
AS Outlook.Application
LOCAL loNameSpace AS Outlook.NameSpace
LOCAL loContacts AS Object
#DEFINE olFolderContacts 10
loOutlook
= CREATEOBJECT('Outlook.Application')
loNameSpace = loOutlook.GetNamespace("MAPI")
loContacts = loNameSpace.GetDefaultFolder(olFolderContacts)
loContacts.Display
One thing to take note of is, that if Outlook is already running you will get a new window with just the contacts page, yet if Outlook is not running you will get the main Outlook window with the
contacts page open, so lets move on.
How do we get object references to the folders?
You can do this in a couple of ways.
1. You can go via the NameSpace.Folders collection like so:

loCalendar = loNameSpace.Folders[1].Folders["Calendar"]
2. The best way is to use the NameSpace.GetDefaultFolder Method like so:

#DEFINE olFolderCalendar
9
loCalendar = loNameSpace.GetDefaultFolder( olFolderCalendar )
At this point I will give you the list of Folders and there appropriate value:
ConstantValueConstantValueolFolderDeleted3olFolderContacts10olFolderOutbox4olFolderJournal11olFolderSent5olFolderNotes12olFolderInBox6olFolderTasks13olFolderCalendar9olFolderDrafts16
New to Outlook 2003 was the Junk folder this Constant is olFolderJunk Value = 23
So with these constants we can get the folders we need, so lets say I wanted to find out how many messages and folders the Inbox contained, so the way to do this is like so:

LOCAL loOutlook
AS Outlook.Application
LOCAL loNameSpace AS Outlook.NameSpace
LOCAL loInBox
AS Object
#DEFINE olFolderInBox

loOutlook
= CREATEOBJECT('Outlook.Application')
loNameSpace = loOutlook.GetNamespace("MAPI")
loInBox
= loNameSpace.GetDefaultFolder(olFolderInBox)
*-- At this point we have the InBox Object.
*-- Lets display how many messages we have in the Inbox.
? We have + TRANSFORM(loInBox.Items.Count) + Messages
*-- What about subfolders in the inbox.
? The inbox contains + TRANSFORM(loInBox.Folders.Count) + SubFolders
This next example obtains any Reminder Messages you have set using the Calendar.

LOCAL loOutlook
LOCAL loReminder

AS Outlook.Application
AS Object

loOutlook = CREATEOBJECT('Outlook.Application')
loReminder = loOutlook.Reminders
? We have + TRANSFORM(loReminder.Count) + Reminders setup
? These are:
FOR EACH loItem IN loReminder
? Caption: + loItem.Caption + ;
DateTime: + TRANSFORM(loItem.OriginalReminderDate)
ENDFOR

http://www.foxite.com/articles/print.aspx?id=72

18/09/2015

OUTLOOK AUTOMATION PART 2 - www.foxite.com - The Home Of The Visual Fox... Page 2 of 2

At this point you can see what the reminders are; you also have the following properties and methods available to you.
NextReminderDate (Property)
IsVisible (Property)
Snooze (Method)
Dismiss (Method)
Snooze takes a variant type parameter which is in minutes; the default is 5 minutes. Both Snooze and Dismiss will give you an OLE Error if the reminder is not visible, so you would have to check
with code like this:

FOR EACH loItem IN loReminder


IF loItem.IsVisible
loItem.Snooze(10)
&& For 10 Mins
&& Or you could dismiss the Item
&& loItem.Dismiss()
ENDIF
ENDFOR
So far all the Automation commands we have used none of these will cause the Outlook Security dialog to be displayed. So going back to working with the Inbox, we know how to obtain the number
of Messages that are in the Inbox, but what if we wanted to find out how many Read and Unread messages were contained within this folder, the code to do this is as follows:

LOCAL
LOCAL
LOCAL
LOCAL
LOCAL

loOutlook
loNameSpace
loInBox
loMess
lnUnRead

AS
AS
AS
AS
AS

Outlook.Application
Outlook.NameSpace
Object
Outlook.MailItem
Integer

#DEFINE olFolderInBox
loOutlook
loNameSpace
loInBox
lnUnRead

=
=
=
=

CREATEOBJECT('Outlook.Application')
loOutlook.GetNamespace("MAPI")
loNameSpace.GetDefaultFolder(olFolderInBox)
0

*-- At this point we have the InBox Object.


*-- Let's display how many messages we have in the Inbox.
? "We have " + TRANSFORM(loInBox.Items.Count) + " Messages"
FOR EACH loMess IN loInBox.Items
IF loMess.UnRead
lnUnRead = lnUnRead + 1
? "UnRead Subject: " + loMess.Subject
ELSE
? "Read Message Subject: " + loMess.Subject
ENDIF
ENDFOR
? "Total of UnRead Messages " + TRANSFORM(lnUnRead)
This code also prints the Subject of the Message; also note at this point we still have not seen the Security dialog.
Lets have a look at some of the methods available to us when we have the Inbox Folder object.
loInBox: Object holding the Inbox Folder.
Items: This contains all the Mail items within the Inbox Folder.
So using the Items Collection we have the following methods available to us:
AlternateRecipientAllowed Delete Move Reply AttachmentAdd DeleteAfterSubmit NoAging ReplyAll AttachmentRead Display Open ReplyAll AutoForwarded DownloadState
OriginatorDelivertReport Requested ReplyRecipientNames (*) AutoResolvedWinner (V11) EnableSharedAttachments (H V11) OutlookInternalVersion ReplyRecipients BCC (*) EntryID
OutlookVersion Save BeforeAttachmentSave ExpiryTime Permission (V11) SaveAs BeforeCheckNames FlagDueBy PermissionService (V11) Saved BeforeDelete FlagIcon (V11) PrintOut
SaveSentMessageFolder BillingInformation FlagRequest PropertyChange Send Body (*) FlagStatus Read Send BodyFormat FormDescription ReadReceiptRequested
SenderEmailAddress (V11 *) Categories Forward ReceivedByEntryID SenderEmailType (V11) CC (*) Forward RecivedByName (*) SenderName (*) ClearConversationIndex
HasCoverSheet (H V11) ReceivedOnBehalfOf EntryID Sensitivity Close HTMLBody (*) ReceivedOnBehalfOfName (*) SentOn Close Importance ReceivedTime SentOnBehalfOfName (*)
Companies InternetCodepage RecipientReassignment Prohibited Size Conflicts (V11) IsConflict Recipients (*) ShowCategoriesDialog ConversationIndex IsIPFax (H V11)
ReminderOverrideDefault Subject ConversationTopic ItemProperties ReminderPlaySound Submitted Copy LastModificationTime ReminderSet To (*) CreationTime Links
ReminderSoundFile UnRead CustomAction MarkForDownload ReminderTime VotingOptions CustomPropertyChange MessageClass RemoteStatus VotingResponse
DeferredDeliveryTime Mileage Reply Write
Key to Above Table:
Colour Description Event Property Property Object Method ReadOnly
Any Item that contains V11 means this is a new property to Outlook 2003.
Any Item that contains H means the item is hidden
Any Item that contains * means the security dialog will be displayed when accessed.
I think that is enough for now, I will continue with this area in the next part of this article, like I said before the Outlook Object model is not small, so this will take time to complete, but hopefully we will
all learn something new about Outlook.

http://www.foxite.com/articles/print.aspx?id=72

18/09/2015

You might also like