Welcome to Foxite.COM Community Weblog Sign in | Join | Help



Outlook Automation Part 3 – Examining the MailItem Properties.

So let’s start with the very basic sending an e-mail, the code for this is:

 

LOCAL loOutlook   AS Outlook.Application

LOCAL loNameSpace AS Outlook.NameSpace

LOCAL loMailItem  AS Outlook.MailItem

LOCAL llShowItem  AS Boolean

 

#DEFINE olMailItem   0

 

loOutlook   = CREATEOBJECT('Outlook.Application')

loNameSpace = loOutlook.GetNamespace("MAPI")

loNameSpace.Logon

loMailItem  = loOutlook.CreateItem( olMailItem )   && This creates the MailItem Object

llShowItem  = .T.

 

WITH loMailItem

    .Subject = “Test Email with VFP Automation”

    .Recipients.Add(“fred.bloggs@bloggsville.com”)

    .Body    = “This is the Main Text of the email“

 

    IF llShowItem

       .Display      && Shows the New Message Dialog with all details from

                      && above filled in. 

    ELSE

       .Send         && Calling this will cause a Security Dialog

    ENDIF

   

ENDWITH

 

I will show how to use Redemption at this point, I will cover this in more depth later on, but I will show it now so that you can see how it bypasses the Security.

 

LOCAL loOutlook   AS Outlook.Application

LOCAL loNameSpace AS Outlook.NameSpace

LOCAL loMailItem  AS Outlook.MailItem

LOCAL loSafeItem  AS Object

 

#DEFINE olMailItem   0

 

loOutlook   = CREATEOBJECT('Outlook.Application')

loNameSpace = loOutlook.GetNamespace("MAPI")

loNameSpace.Logon

loMailItem  = loOutlook.CreateItem( olMailItem )   && This creates the MailItem Object

loSafeItem  = CREATEOBJECT(‘Redemption.SafeMailItem’)

 

WITH loSafeItem

    .Item    = loMailItem     && This attaches the Mail Object to

                              && Redemption SafeMailItem Object

    .Recipients.Add(“fred.bloggs@bloggsville.com”)

    .Subject = “Test Email with VFP & Redemption”

    .Body    = “This is the Main Body of the Message”

    .Send   && this does not cause the Security Dialog to be displayed.

ENDWITH

 

 


Another way to add recipients to the Message is to use the ‘To’ Property but this is not the Recommended way, it is better to use the ‘Recipients.Add’ method.

 

This next table shows the Properties you will most likely use:

 

Property

Type

Description

Subject

Character

This is the Subject of the Message, you also can use this as an index into the Items Collection

Body

Character

This is the Main Text of the Message

Recipients

Object

This is the Recipient Collection Object, you need to call this for every person you wish to send the mail to

To

Character

This is a Semi colon separated list of recipients you wish to send the mail to, recommended way is to use the Recipients Object

CC

Character

This is also a Semi colon separated list of people receiving copies, likewise it is recommended way is again to use the Recipients Object

BCC

Character

This is also a Semi colon separated list of people receiving blind copies, likewise it is recommended way is again to use the Recipients Object

Importance

Numeric

The Priority of the message, this corresponds to the Importance field in the Options dialog.

olImportanceLow

0

olmportanceNormal

1 (Default)

olImportanceHigh

2

Sensitivity

Numeric

The Privacy level of the Message, this corresponds to the Sensitivity field in the Options dialog.

olNormal

0

olPersonal

1

olPrivate

2

olConfidential

3

Attachments

Object

This is Collection used to Add attachments to the message object.

 

Right so let’s look at the other properties of the MailItem.

 

Property: AlternateRecipientAllowed

This is a Read/Write Property and is a Boolean value, will be True if the mail message can be forwarded.

 

Property: AutoForwarded

This is a Read/Write Property and is a Boolean value, will be True if the mail message was automatically forwarded.

 

Property: AutoResolvedWinner                       - New in Outlook 2003.

This is a Read only Property and is a Boolean value, True determines if the item is a winner of an automatic conflict resolution. A value of False does not indicate that the item is a loser of an automatic conflict resolution; the item should be in conflict with another item.

Example:

*-- This example requires you have Outlook already open

*-- and one of the Mail items is selected.

LOCAL loOutlook  AS Outlook.Application

LOCAL loMailItem AS Outlook.MailItem

 

loOutlook = CREATEOBJECT('Outlook.Application')

 

loMailItem = loOutlook.ActiveInspector.CurrentItem

IF loMailItem.Conflicts.Count > 0

    IF loMailItem.AutoResolvedWinner

       MESSAGEBOX("This Item is a winner in an automatic conflict resolution")

    ELSE

       MESSAGEBOX("This item is a loser in an automatic conflict resolution.")

    ENDIF

ELSE

    MESSAGEBOX("This item is not in conflict with any item.")

ENDIF

 

 

Property: BillingInformation

This is a Read/Write Property and is free-form text, Returns or sets the value representing the billing information associated with the item.

 

Property: BodyFormat

This is a Read/Write Property and is numeric, Returns or sets the Body format of the Body text, Outlook provides three text options and these are: Plain Text, Rich Text and HTML.

Example:

 

LOCAL loOutlook  AS Outlook.Application

LOCAL loMailItem AS Outlook.MailItem

 

#DEFINE olMailItem   0

#DEFINE olFormatHTML 2

 

loOutlook  = CREATEOBJECT(‘Outlook.Application’)

loMailItem = loOutlook.CreateItem( olMailItem )

WITH loMailItem

    && Set body format to HTML

    .BodyFormat = olFormatHTML

    .HTMLBody   = “<HTML><H2>The body of this message will appear in HTML.” + ;

                  “</H2><BODY>Type the Message text here.</BODY></HTML>”

    .Display

ENDWITH

 

The other type constants are:

Constant

Value

olFormatUnspecified

0

olFormatPlain

1

olFormatHTML

2

olFormatRichText

3

 

All text formatting will be lost when the BodyFormat property is switched from RTF to HTML and vice-versa. In earlier versions of Outlook, the BodyFormat property returned the olFormatUnspecified constant for a newly created item that has not been displayed or whose BodyFormat property is not yet set programmatically. In Microsoft Office Outlook 2003, the property returns the format that is currently set in the Outlook user interface.

 

Property: Categories

This is a Read/Write property and is of string value; you can return or set the string representing the category assigned to the form description.

Example:

 

LOCAL loOutlook  AS Outlook.Application

LOCAL loMailItem AS Outlook.MailItem

 

#DEFINE olMailItem   0

 

loOutlook  = CREATEOBJECT(‘Outlook.Application’)

loMailItem = loOutlook.CreateItem( olMailItem )
WITH loMailItem
    .Subject    = “Test for Categories dialog”

    .Categories = “Ideas”

    .Display

    .ShowCategoriesDialog

ENDWITH

 

Property: Companies

This is a Read/Write property and is of string value; you can return or set the string representing the names of companies associated with the item.


Property: ConversationIndex

This is a Read only property and is of string value; the value returned represents the index of the conversation thread of the item.

 

Property: ConversationTopic

This is a Read only property and is of string value; the value returned represents the topic of the conversation thread of the item.

 

Property: CreationTime

This is a Read only property and is of DateTime value; the value returned is the Date and Time that the item was created.

 

Property: DeferredDeliveryTime

This is a Read/Write property and is of DateTime value; you can return or set the date & time for when the Message is to be delivered. Example:

LOCAL loOutlook  AS Outlook.Application

LOCAL loMailItem AS Outlook.MailItem

 

#DEFINE olMailItem   0

 

loOutlook  = CREATEOBJECT(‘Outlook.Application’)

loMailItem = loOutlook.CreateItem( olMailItem )

 

WITH loMailItem

    .Subject    = “Test for deferred delivery time”

    .DeferredDeliveryTime = “10/10/2005 17:00”

    .Display

ENDWITH

 

To check this has been set select the View/Options from the menu of the mail item, and check the Do Not Delivery before option.

 

Property: DeleteAfterSubmit

This is a Read/Write property and is of Boolean value; if this value is True then a copy of the message is not saved when it has been sent, if False then a copy of the message will be saved.

 

Property: DownloadState

This is a Read only property and is a numeric value; the value of this property represents the download state of the item.

Constant

Value

olFullItem

1

olHeaderOnly

0

                Example:

LOCAL loOutlook AS Outlook.Application

LOCAL loInBox   AS Outlook.MAPIFolder

LOCAL loItems   AS Outlook.Items

LOCAL loObj     AS Outlook.MailItem

LOCAL lnI       AS Integer, liCount AS Integer

 

#DEFINE olFolderInbox             6

#DEFINE olHeaderOnly       0

#DEFINE olMarkedForDownload 2

 

loOutlook = CREATEOBJECT('Outlook.Application')

loInBox   = loOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

loItems   = loInbox.Items

liCount   = loItems.Count

 

FOR lnI = 1 TO liCount

    loObj = loItems.Item[lnI]

    *-- Verify if the state of the item is olHeaderOnly

    IF loObj.DownloadState = olHeaderOnly

       MESSAGEBOX("This item has not been fully downloaded.")

       *-- Mark the item to be downloaded.

       loObj.MarkForDownload = olMarkedForDownload

       loObj.Save

    ENDIF

ENDFOR       

Property: EnableSharedAttachments               - New in Outlook 2003.

This is a Read/Write property and is of Boolean value; the value of this property determines whether the Attachment Options task pane will be displayed in the Outlook user interface for an e-mail item.

 

Property: EntryID

This is a Read only property of string value, the value returned is the unique entry ID of the object. A MAPI store provider assigns a unique ID string when an item is created in its store. Therefore, the EntryID property is not set for a Microsoft Outlook item until it is saved or sent. The EntryID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved. The EntryID property returns a MAPI long-term EntryID. For more information about long- and short-term EntryIDs, search http://msdn.microsoft.com for PR_ENTRYID.

 

Property: ExpiryTime

This is a Read/Write property of DateTime value, this value indicates at which date and time the item becomes invalid and can be deleted.

Example:

LOCAL loOutlook  AS Outlook.Application

LOCAL loMailItem AS Outlook.MailItem

 

#DEFINE olMailItem   0

 

loOutlook  = CREATEOBJECT('Outlook.Application')

loMailItem = loOutlook.CreateItem( olMailItem )

WITH loMailItem

    .To         = "Fred Bloggs"

    .Subject    = "Test for Expiry"

    .ExpiryTime = "10/08/2005 17:00"

    .Display

ENDWITH

 

Property: FlagDueBy          

This is a Read/Write property and is of DateTime value, this value specifies a date & time by which the e-mail message is due, this property is only valid if the FlagStatus Property is also set for the message.

 

Property: FlagIcon                                               - New in Outlook 2003.

This is a Read/Write property and is of numeric value, Outlook 2003 has 7 flag types, these can either be returned or set, the values are:

Constant

Value

Constant

Value

olNoFlagIcon

0

olYellowFlagIcon

4

olPurpleFlagIcon

1

olBlueFlagIcon

5

olOrangeFlagIcon

2

olRedFlagIcon

6

olGreenFlagIcon

3

 

 

Example:

LOCAL loOutlook AS Outlook.Application

LOCAL loInBox   AS Outlook.MAPIFolder

LOCAL loItem    AS Outlook.MailItem

LOCAL lnI       AS Integer

 

#DEFINE olFolderInbox             6

#DEFINE olYellowFlagIcon   4

 

loOutlook = CREATEOBJECT('Outlook.Application')

loInBox   = loOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

*-- Find the Sender Name of Support and change the flagicon.

FOR lnI = 1 TO loInBox.Items.Count

    loItem = loInBox.Items[lnI]

    IF loItem.SenderName = "Support"     && Security Dialog...

        loItem.FlagIcon = olYellowFlagIcon

         loItem.Save

    ENDIF

ENDFOR

Property: FlagRequest

This is a Read/Write property and is of string value, this value indicates the requested action for an e-mail message, and this property is only valid if the FlagStatus property is also set for the message.

 

Property: FlagStatus

This is a Read/Write property and is of Numeric, this value indicates the flag status for the mail message. The constants are:

Constant

Value

olFlagComplete

1

olFlagMarked

2

olNoFlag

0

 

 

Property: HasCoverSheet                                   - New in Outlook 2003.

This is a Read/Write property and is of Boolean value, the value determines the setting of the Use Cover Sheet option in the Fax UI, which in turn controls what is displayed in the body of the mail item.

 

Property: HTMLBody

This is a Read/Write property of string type, this value should be valid HTML syntax.

Setting the HTMLBody property sets the EditorType property of the Items’s Inspector to olEditorHTML.  Setting the HTMLBody property will always update the Body property immediately, also note that if you set the Body property this will clear the contents of the HTMLBody property.

 

Property: InternetCodePage

This is a Read/Write property of Long type, this value determines the Internet Code Page used by the item, the Internet code page defines the text encoding scheme used by the item.

 

Property: IsConflict

This is a Read only Property of Boolean type, the value returned determines if the e-mail item is in conflict, whether or not an item is in conflict is determined by the state of the application. For example, when a user is offline and tries to access an online folder the action will fail and in this scenario the IsConflict property will return true. Example Code:

LOCAL loOutlook  AS Outlook.Application

LOCAL loMailItem AS Outlook.MailItem

 

loOutlook  = CREATEOBJECT('Outlook.Application')

loMailItem = loOutlook.CreateItem(0)

WITH loMailItem

    .Body = "This e-mail message was created automatically on " + ;

                       TTOC(DATETIME())

    .To   = "fbloggs@bloggsville.com"

    IF !.IsConflict

       .Send         && Security Dialog

    ELSE

       MESSAGEBOX("Conflict: Cannot send item")

    ENDIF

ENDWITH

loMailItem = .NULL.

loOutlook  = .NULL.

           

Property: IsIPFax                                                  - New in Outlook 2003.

This is a Read/Write property of Boolean type, the value determines if the mail item is a fax.

 


Property: LastModificationTime

This is a Read only property of DateTime value; this value returns the date and time the item was last modified.

 

Property: MarkForDownload

This is a Read/Write property of numeric value; the value determines the status of an item once it is received by a remote user. This property gives remote users with less-than-ideal data-transfer capabilities increased messaging flexibility. Constants are:

Constant

Value

Description

olMarkedForCopy